在scapython中读取数据包时将十六进制转换为ascii

2024-06-28 20:00:15 发布

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

我正在尝试将十六进制转换为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

Tags: inrawlineasciifiledecodehexx00