saving hexdump(packet) to list in scapy

情到浓时终转凉″ 提交于 2019-12-11 13:36:38

问题


Is there any way I could save hexdump() to byte list so the list can be accessed by index. what I need is like this

byte = hexdump(packet)
for i in range(0, len(byte)):
print %x byte[i]

回答1:


The byte content of the packet may be accessed by invoking str(packet), as follows:

content = str(packet) # decoded hex string, such as '\xde\xad\xbe\xef'
print content
for byte in content:
    pass # do something with byte

EDIT - This answer specifies how this can be converted to a byte array, for example:

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


来源:https://stackoverflow.com/questions/28147515/saving-hexdumppacket-to-list-in-scapy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!