Python scapy 从数据包中提取字段
Python scapy extracting field from packet
我需要帮助从 scapy 捕获的数据包中提取一个字段并将其推送到一个变量中进行处理。
Q: 我想将 'notdecoded' 字段数据捕获到一个变量中。
捕获使用:
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'
要从 scapy 数据包中提取字段,请使用 pkt[Layer].field
等语法(要从 TCP 层提取 dport 字段,请使用 pkt[TCP].dport)。
pkt[RadioTap].notdecoded
应该适用于您的情况。
我需要帮助从 scapy 捕获的数据包中提取一个字段并将其推送到一个变量中进行处理。
Q: 我想将 'notdecoded' 字段数据捕获到一个变量中。
捕获使用:
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'
要从 scapy 数据包中提取字段,请使用 pkt[Layer].field
等语法(要从 TCP 层提取 dport 字段,请使用 pkt[TCP].dport)。
pkt[RadioTap].notdecoded
应该适用于您的情况。