使用scapy进行无线数据包捕获
我尝试过的代码如下:
from scapy.all import *
def PacketHandler(pkt) :
if pkt.haslayer == 2 and pkt.subtype==0:
if pkt.haslayer(IP) :
ip=pkt.getlayer(IP)
print ip.dst
if pkt.haslayer(UDP):
udp=pkt.getlayer(UDP)
print udp.dport
if pkt.haslayer(TCP) :
tcp=pkt.getlayer(TCP)
print tcp.port
sniff(iface="mon0", prn=PacketHandler)
我想用这个代码捕获所有无线数据包,但我只收到了多播(IP/UDP)数据包。那么,我该怎么才能在我的无线网络中获取所有的数据包呢?为了这个目的,我暂时关闭了接入点的加密,这样我就能访问数据包中的信息。
1 个回答
6
如果你只想处理 Data
帧,而不想处理 Management
和 Control
帧,你可以这样做:
from scapy.all import *
def packet_handler(pkt) :
# if packet has 802.11 layer, and type of packet is Data frame
if pkt.haslayer(Dot11) and pkt.type == 2:
# do your stuff here
print(pkt.show())
sniff(iface="mon0", prn=packet_handler)
你还可以使用 sniff
函数的 filter
选项,只让 Data
帧发送到你的 packet_handler
函数:
from scapy.all import *
def packet_handler(pkt) :
# if packet has 802.11 layer
if pkt.haslayer(Dot11):
# do your stuff here
print(pkt.show())
sniff(iface="mon0", prn=packet_handler, filter="type Data")
这里 有一个关于帧的 type
和 subtype
值的好列表。