我的代码我尝试过如下:
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)数据包。那么如何才能在我的无线网络中获取所有DATA数据包?我已经在我的接入点上禁用了加密(暂时),因此我可以访问数据包中的数据。
答案 0 :(得分:5)
如果您只想处理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)
此外,您可以使用filter
功能的sniff
选项仅过滤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")
Here是一个很好的框架type
和subtype
值列表。