Search code examples
python-2.7scapypayloadpackets

Python's Scapy can't print load


I am new to Scapy, I recently tried creating a program that would search for packets and print them.

When I ran the program,

from scapy.all import *
a = sniff(iface='enp0s3', count=1)
l = a[0].load
print l

it gave the output of

!f��B    2�.�I�b��"�����.�KS���

However, when running the program in the interactive Scapy shell, running

a[0].load

it gives:

\x17\x03\x03\x00!f\x1d\xf3\xb0B\x15\t2\x86.\xcbI\xddb\xaa\xf1"\x03\xf1\x8c\x91\xda\xd3.\xf3\x08\xe7K\x05S\xfe\x96\xac

This is the payload of a packet. How can I convert the symbols outputted from the script to something like what I got when running it in the interactive shell?


Solution

  • Maybe you can try this:

    print " ".join(hex(ord(n)) for n in a[0].load)
    

    Source: Print a variable in hexadecimal in Python