首页 > 其他分享 >scapy抓包学习

scapy抓包学习

时间:2022-10-19 22:13:15浏览次数:73  
标签:get route scapy 学习 conf print import 抓包

1、列出接口

使用 get_if_list() 获取接口列表

from scapy.all import sniff, rdpcap, load_layer, conf, get_if_list
ifaces = get_if_list()
print(ifaces)

您也可以使用 conf.ifaces 对象来获取接口。在本例中,对象首先显示为列。然后 dev_from_index() 用于访问索引2处的接口。

from scapy.all import sniff, rdpcap, load_layer, conf, get_if_list
ifaces = conf.ifaces
print(ifaces)
print(ifaces.dev_from_index(1))

(1)IPv4路由

这些路线都在 conf.route . 您可以使用它来显示路由,或获取特定的路由

from scapy.all import sniff, rdpcap, load_layer, conf, get_if_list
routes = conf.route
print(routes)

获取特定IP的路由: conf.route.route() 将返回 (interface, outgoing_ip, gateway)

from scapy.all import sniff, rdpcap, load_layer, conf, get_if_list
routes = conf.route
print(routes)
print(routes.route("127.0.0.1"))

IPv6路由

与IPv4相同,但 conf.route6

(2)获取路由器IP地址

gw = conf.route.route("0.0.0.0")[2]

(3)获取接口的本地IP/IP

from scapy.all import get_if_addr
ip = get_if_addr(conf.iface)  # default interface
ip = get_if_addr("Intel(R) Wireless-AC 9560 160MHz")
print(ip)

(4)获取接口的本地MAC/MAC

from scapy.all import get_if_hwaddr
mac = get_if_hwaddr(conf.iface)  # default interface
mac = get_if_hwaddr("eth0")
print(mac)

(5)通过IP获取MAC

from scapy.layers.l2 import getmacbyip
mac = getmacbyip("10.0.0.1")
print(mac)

2、scapy支持的数据包类型

from scapy.all import ls
from scapy.layers.inet import IP
# 输出scapy支持的数据包类型
print(ls())
# 使用ls(IP())可以查看IP数据包的参数
print(ls(IP))

(1)构建一个数据包

(2)堆栈层

3、捕获数据包

  • sniff()函数可帮助我们捕获所有流量:
  • 包括countfilterifacelfilterprntimeout选项。

 

标签:get,route,scapy,学习,conf,print,import,抓包
From: https://www.cnblogs.com/windyrainy/p/16808036.html

相关文章

  • JavaScript学习--String对象,自定义对象,window对象
    String对象定义:var变量名=newString(s);varstr=newString("hello");var变量名=s;           varstr="hello";属性:length字符串长度方法:c......
  • 【JavaWeb】会话的学习笔记:Cookie和Session的知识点,这一次我总算学明白了
    @[Toc]1会话1.1什么是会话?用户打开浏览器,访问Web服务器的资源,会话建立,直到有一方断开连接,会话结束。在一次会话中可以包含多次请求和响应。1.2会话跟踪一种维护浏览器状......
  • Python学习路程——Day18
    Python学习路程——Day18包的具体使用''' 虽然在python3中对包的要求低了,不需要__init__.py文件也可以识别,但是为了兼容性考虑,我们最好还是要加上__init__.py 1、如果......
  • shell学习笔记(二)
    特殊符号:    {}集合${}变量引用#pingipip=10.10.19.10i=1while[$i-le5]doping-c1$ip&>dev/nullif[$?-eq0];thenecho"$ipisup.."fileti......
  • yolo系列学习
    yolo系列学习yolov6配置&试运行yolo模型结构&训练策略解析......
  • 《PyTorch深度学习实践》-刘二大人 第三讲
    #梯度下降法frommatplotlibimportpyplotasplt#preparethetrainingsetx_data=[1.0,2.0,3.0]y_data=[2.0,4.0,6.0]#initialguessofweightw=......
  • sql学习笔记-函数
    SQLAVG()语法SELECTAVG(column_name)FROMtable_name求平均数SQLCOUNT(column_name)语法COUNT(column_name)函数返回指定列的值的数目(NULL不计入):SELECTCO......
  • 深度学习中的patch是什么?和block的区别?
    patch就是输入图像中的一个小块而block像ResNet中的ResBlock这种块,块里面包括了卷积、归一化层、激活函数等,如下图所示patch和block本质上是不同的概念,只是中文翻译都可......
  • haskell 学习笔记——关于monad
    前言:haskell真是一门让人又爱又恨的语言,学习起来的难度也是相当之大,重点在于理解概念与每一步递归的进行,即使学了一月有余我依然被各种syntaxerror所折磨,而且对于一些深入......
  • 通俗讲解集成学习算法!
    作者:黄星源,Datawhale优秀学习者本文以图文的形式对模型算法中的集成学习,以及对集中学习在深度学习中的应用进行了详细解读。集成学习集成学习,即分类器集成,通过构建并结合多......