Search code examples
pythonscapy

Why am i getting the result expected in scapy?


import scapy.all as scapy

p = scapy.sniff(filter='tcp', count=1)
d = p.show()

print(scapy.hexraw(d))

RESULT:

AttributeError: module 'scapy.all' has no attribute 'hexraw'

Why am i getting this error


Solution

  • hexraw is a method of the PacketList class not a function of scapy.all. Moreover, the show method of the Packet class returns None: it prints something to the standard output but does not return anything. So doing d = p.show() does not make any sense. I don't know what your goal initially was, but you could try instead:

    p.show()  # print the packet list
    p[0].show()  # print the first packet of the list
    p.hexraw() # print a summary of the packet list with Raw layers being hexdumped