将hexdump(packet)保存到scapy中 [英] saving hexdump(packet) to list in scapy

查看:243
本文介绍了将hexdump(packet)保存到scapy中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以将hexdump()保存到字节列表,以便可以通过索引访问列表.我需要的就是这样

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]

推荐答案

可以通过调用str(packet)来访问数据包的字节内容,如下所示:

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

这篇关于将hexdump(packet)保存到scapy中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆