2014-03-26 49 views
0

我的代碼,我試圖幫助捕捉如下:無線數據分組與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)數據包。那麼我怎樣才能在我的無線網絡中獲得所有的數據包?我已經在我的接入點上禁用了加密(暫時),所以我可以訪問數據包中的數據。

+0

你可以在'mon0'接口上用'wireshark'看到它們嗎? –

+0

我認爲你必須嗅探混雜模式https://en.wikipedia.org/wiki/Promiscuous_mode另外,請注意,並非所有的網絡適配器都支持混雜模式。 –

+0

@OmidRaha:是的,我可以在mont0接口上的wireshark上看到它們...... – user3292475

回答

4

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

Here,是type和一個好名單幀的值。