有什么办法可以将hexdump()保存到字节列表中,这样就可以通过索引访问列表了。我需要的是这样的
byte = hexdump(packet)
for i in range(0, len(byte)):
print %x byte[i]
答案 0 :(得分:1)
可以通过调用str(packet)
来访问数据包的字节内容,如下所示:
content = str(packet) # decoded hex string, such as '\xde\xad\xbe\xef'
print content
for byte in content:
pass # do something with byte
编辑 - This answer指定如何将其转换为字节数组,例如:
byte_array = map(ord, str(packet)) # list of numbers, such as [0xDE, 0xAD, 0xBE, 0xEF]
print byte_array
for byte in byte_array:
pass # do something with byte