2015-07-21 704 views
0

我需要幫助從scapy捕獲的數據包中提取一個字段,並將其推入一個變量進行處理。Python scapy從數據包中提取字段

問:我想捕獲'未解碼'字段數據到一個變量。

捕獲使用:

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 == 0: 
      # do your stuff here 
      print(pkt.show()) 


sniff(iface="wlan0mon", prn=packet_handler) 

輸出:Complete Output at Pastebin

###[ RadioTap dummy ]### 
    version = 0 
    pad  = 0 
    len  = 36 
    present = TSFT+Flags+Rate+Channel+dBm_AntSignal+b14+b29+Ext 
    notdecoded= ' \x08\x00\x00\x00\x00\x00\x00\xf4\x82\xc2\xc6\x01\x00\x00\x00\x10\x02\x99\t\xa0\x00\xb1\x00\x00\x00\xb1\x00' 

回答

1

爲了提取從Scapy的分組中的字段使用語法等pkt[Layer].field(用於從使用TCP層提取DPORT場PKT [TCP] .dport)。

pkt[RadioTap].notdecoded應該適用於您的情況。