0

I building a sniffer and I want to take the data from the Raw layer of a packet and show it as hexdump in a wx.TextCtrl. let's say the Raw is ABC it will show 65 66 67. I tried :

self.txt.SetLabelText(" ".join(map(hex,str(pkt[Raw]))))

It raises TypeError: hex() argument can't be converted to hex

Is there any known way to do it? I am familiar with hexdump(pkt) but it prints the hexdump and also the conversion to string and also doesn't return it..

oridamari
  • 561
  • 7
  • 12
  • 24
  • Try converting from raw to an integer, or even raw to string to integer: http://stackoverflow.com/questions/21669374/convert-string-to-hex-in-python – Jonathan Epstein Mar 05 '15 at 16:30

1 Answers1

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

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

conf.raw_layer = MyRaw
mungayree
  • 313
  • 1
  • 12