If you want to handle only Data
frames, and not Management
and Control
frames, then you can do this:
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)
Also you can use filter
option of sniff
function to filter only Data
frames to go to your packet_handler
function:
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, is a good list of type
and subtype
values for frames.