Reputation: 93
I'm attempting to convert hex to ascii but am having extreme difficulty in doing so --
>>> 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
Upvotes: 2
Views: 7252
Reputation: 8147
In Scapy the str()
function will return a hex string on a packet for you.
From 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'
Once you convert it, you can reimport it back into Scapy. All mentioned in the documentation I pointed out.
Upvotes: 1