Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python从数据包中提取字段_Python_Wireless_Scapy_Packet Capture_Wifi - Fatal编程技术网

Python从数据包中提取字段

Python从数据包中提取字段,python,wireless,scapy,packet-capture,wifi,Python,Wireless,Scapy,Packet Capture,Wifi,我需要帮助从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:

我需要帮助从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)
输出:


要从scapy数据包中提取字段,请使用类似于
pkt[Layer].field的语法(要从TCP层提取dport字段,请使用pkt[TCP].dport)

pkt[RadioTap].notdecoded
应该适用于您的情况

###[ 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'