我可以.pcap
用pyshark
. 这是我的代码:
packets = pyshark.FileCapture(pcap_dir) # pcap_dir is the directory of my pcap file
要打印数据包,我使用print(packets[0])
. 我的问题是:我怎样才能转换packets[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)
此外,检查这个可能很有用