gpt4 book ai didi

python - 如何使用Python从hexdump中提取数据包信息?

转载 作者:行者123 更新时间:2023-12-01 02:13:21 24 4
gpt4 key购买 nike

我正在开发一个网络项目,其中有数据包的十六进制转储,我需要剖析该十六进制转储数据包以显示所有数据包信息。

示例:数据包信息字段 -

source address
destination address
encapsulation type
frame number
frame length
FCS
data
epoch time

我们不应该使用文件作为输入和输出,因为它会增加内存利用率并可能使服务器崩溃。

我尝试使用以下代码,但这在我的情况下不起作用:

# imports scapy Utility

from scapy.all import *
from scapy.utils import *

# variable to store hexdump

hexdump = '0000 49 47 87 95 4a 30 9e 9c f7 09 70 7f....'

# Initialize a 802.11 structure from raw bytes

packet = Dot11(bytearray.fromhex(hexdump))

#scapy function to view the info

packet.summary()
packet.show()

由于我是这项技术的新手,有什么建议可以实现这一目标吗?我可能缺乏一些正确的指示来解决这个问题。

最佳答案

您的 hexdump 值似乎包含索引。删除它:

  • 在 Scapy >= 2.4rc 上:

    data = hex_bytes('49 47 87 95 4a 30 9e 9c f7 09 70 7f [...]'.replace(' ', ''))
  • 或者使用 Python 2 和 Scapy <= 2.3.3:

    data = '49 47 87 95 4a 30 9e 9c f7 09 70 7f [...]'.replace(' ', '').decode('hex')

然后:

Dot11(data)

关于python - 如何使用Python从hexdump中提取数据包信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48577749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com