我能够用.pcap
读取pyshark
文件。这是我的代码:
packets = pyshark.FileCapture(pcap_dir) # pcap_dir is the directory of my pcap file
要打印数据包,我使用print(packets[0])
。我的问题是:如何将packets[0]
转换为其二进制值?例如,如果我想再次将数据包发送到网络,这会很有用
答案 0 :(得分:0)
我能够解决问题。我只是用:
packets = pyshark.FileCapture(
input_file=pcap_dir,
use_json=True,
include_raw=True
)._packets_from_tshark_sync() # pcap_dir is the directory of my pcap file
hex_packet = packets.__next__().frame_raw.value
print(hex_packet)
binary_packet = bytearray.fromhex(hex_packet)
print(binary_packet)
此外,检查this
可能会很有用