gpt4 book ai didi

python - 在 scapy 中读取数据包时将十六进制转换为 ascii -- Python

转载 作者:太空宇宙 更新时间:2023-11-04 06:08:30 25 4
gpt4 key购买 nike

我正在尝试将十六进制转换为 ascii,但这样做非常困难 --

>>> pkt[9][3].sprintf("%Raw.load%")
"'\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x1d\\x01\\x04\\xfe\\t\\x00\\xb4\\xc0\\xa8\\x00!\\x00'"

>>> pkt[9][3].sprintf("%Raw.load%").decode("hex")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/encodings/hex_codec.py", line 42, in hex_decode
output = binascii.a2b_hex(input)
TypeError: Odd-length string

最佳答案

在 Scapy 中,str() 函数将为您返回数据包上的十六进制字符串。

来自 Scapy Hex String -

>>> pkt_str = str(pkt)
>>> pkt_str
'\x00PV\xfc\xceP\x00\x0c)+S\x19\x08\x00E\x00\x00T\x00\x00@\x00@\x01Z|\xc0\xa8
\x19\x82\x04\x02\x02\x01\x08\x00\x9c\x90Za\x00\x01\xe6\xdapI\xb6\xe5\x08\x00
\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b
\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./01234567'

转换后,您可以将其重新导入回 Scapy。我指出的文档中提到的所有内容。

关于python - 在 scapy 中读取数据包时将十六进制转换为 ascii -- Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20409844/

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