我正在尝试使用 Pyshark 读取 .pcap 文件中所有数据包的有效负载。我能够打开和读取文件,访问数据包及其其他信息,但我无法找到用于访问数据包有效负载的正确属性/方法。有什么建议么 ?有没有其他方法可以使用 python for windows 10 读取 .pcap 文件中的数据包有效负载?
(我尝试使用 Scapy 而不是 Pyshark,但显然在 Windows 上运行 Scapy 存在一些问题,它在我的系统上也不起作用)
我在 Internet 和 StackOverflow 上的 pyshark 项目的不同代码片段中发现了这些行。我尝试了它们,但它们都不起作用:
import pyshark
cap = pyshark.FileCapture('file.pcap')
pkt = cap[1]
#for other information
print(pkt.tcp.flags_ack) #this works
print(pkt.tcp.flags_syn) #this works
print(pkt.tcp.flags_fin) #this works
#for payload
print(pkt.tcp.data) #does not work, AttributeError
print(pkt.tcp.payload) #does not work, AttributeError
print(pkt.data.data) #does not work, AttributeError