如何将pyshark数据包转换为二进制值

2024-06-11 16:53:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以用pyshark读取.pcap文件。这是我的代码:

packets = pyshark.FileCapture(pcap_dir) # pcap_dir is the directory of my pcap file

要打印数据包,我使用print(packets[0])。我的问题是:如何将packets[0]转换为其二进制值?例如,如果我想再次将数据包发送到网络,这将非常有用


Tags: 文件ofthe代码ismydirpcap
1条回答
网友
1楼 · 发布于 2024-06-11 16:53:33

我能解决这个问题。我只是用了:

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

相关问题 更多 >