sockets - Python decoding UDP -
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 can see of data has been decoded/interpreted rest isn't not sure why
can help?
you're printing raw udp packets, contain arbitrary binary data. of bytes in printable range, aren't in range converted �.
you can better @ data printing representation, shows printable bytes normal , shows unprintable ones hexadecimal escape codes. that, change print
statement to:
print repr(s.recv(2048))
i suspect you'd decode packets. that's quite possible, it's bit technical, , should study topic bit first. :) article silver moon, code network packet sniffer in python linux, looks quite helpful.
Comments
Post a Comment