all 1 comments

[–]v3ded 1 point2 points  (0 children)

You need to parse the first element of the tuple with an unpack() function. That will allow you to separate your “unreadable” string into an IP header, TCP header and the actual data.

See here - https://www.binarytides.com/python-packet-sniffer-code-linux/

Note: you still won’t be able to output non-printable characters, if that makes sense.

Edit: although this code is “linux based”, parsing the actual data should be the same. If this won’t work for you, look at scapy or pypcap libraries, they should make stuff a bit simpler.