code:
import socket, binascii, struct
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
while True:
print s.recv(2048)
output:
Ek�9@@�F5��W�jq��� stackexchangecom� electronics �
h hstackexchangecomDa�scifi ET@@�<���� stackoverflowcom���meta ,��� stackoverflowcom�A���meta ,��� stackexchangecomG��security Ee@@�+���� stackexchangecom���scifi
as you can see some of the data has been decoded/interpreted but the rest isn't not sure as to why
Can anyone help?
You're printing raw UDP packets, which contain arbitrary binary data. Some of those bytes are in the printable range, but those that aren't in that range get converted into �.
You can get a better look at that data by printing its representation, which shows the printable bytes as normal and shows the unprintable ones as hexadecimal escape codes. To do that, change your print statement to:
print repr(s.recv(2048))
I suspect you'd like to actually decode those packets. That's quite possible, but it's a bit technical, and you should probably study the topic a bit first. :) This article by Silver Moon, Code a network packet sniffer in python for Linux, looks quite helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With