Search code examples
pythonwirelessscapypacket-capturewifi

Python scapy extracting field from packet


I need help extracting a field from the scapy captured packet and pushing it into a variable for processing.

Q: I would like to capture the 'notdecoded' field data into a variable.

Capturing using:

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)

Output: 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'

Solution

  • To extract a field from scapy packet you use syntax like pkt[Layer].field (for extracting dport field from TCP layer you use pkt[TCP].dport).

    pkt[RadioTap].notdecoded should work in your case.