簡體   English   中英

借助Scapy捕獲無線數據包

[英]Wireless Data Packet Capturing with help of 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) 

使用此方法,我想捕獲所有無線DATA數據包,但僅得到多播(IP / UDP)數據包。 那么,如何獲取無線網絡中的所有DATA數據包? 我為此暫時禁用了訪問點上的加密,以便可以訪問數據包中的數據。

如果您只想處理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)

您也可以使用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")

是一個很好的列表,列出了幀的typesubtype值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM