scapy - 如何显示(编码十六进制)而不是str

时间:2015-03-23 17:46:32

标签: python scapy

我已经定义了以下 -

class PadChecksum(Packet):
    name = "PadChecksum"
    fields_desc = [ StrField("data", None) ]

conf.raw_layer = PadChecksum

如何显示如下?

###[ PadChecksum ]###
       data      = '\x00\x00\x00\xa8L\xa8\xe5'

as

###[ PadChecksum ]###
       data      = '00 00 00 a8 4c a8 e5'

如何更准确地显示如下?

###[ PadChecksum ]###
       pad      = '00 00 00'
       checksum = 'a8 4c a8 e5'

1 个答案:

答案 0 :(得分:2)

得到它!!

class XStrField(StrField):
      def i2repr(self, pkt, x):
            return ' '.join(b.encode('hex') for b in x)

class PadChecksum(Packet):
    name = "PadChecksum"
    fields_desc = [ XStrField("data", None) ]

显示 -

###[ PadChecksum ]###
       data      = 00 00 00 eb 62 aa 9d