无线数据包捕获scapy的帮助

时间:2014-03-26 18:52:57

标签: python security wireless scapy intrusion-detection

我的代码我尝试过如下:

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数据包?我已经在我的接入点上禁用了加密(暂时),因此我可以访问数据包中的数据。

1 个答案:

答案 0 :(得分:5)

如果您只想处理Data帧,而不是ManagementControl帧,那么您可以这样做:

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是一个很好的框架typesubtype值列表。