I am developing a python sniffer which sniff the udp packets. I use this code to receive and get the payload of the received packet in human readable format, but the printed payload is not human readable! I searched about converting this format to human readable, but I got nothing.
packet = recv_socket.recvfrom(65565)
packet = packet[0]
ip_header = packet[0:20]
iph = struct.unpack('!BBHHHBBH4s4s', ip_header)
data = packet[28:]
payload = ":".join("{:02x}".format(ord(c)) for c in data)
print payload.decode("utf-8", "ignore")
print payload
Right now, the out put of print commands are as follow:
.*###[ DNS ]###
id = 1382
qr = 0L
opcode = 12L
aa = 0L
tc = 0L
rd = 1L
ra = 0L
z = 1L
ad = 1L
cd = 0L
rcode = 12L
qdcount = 30062
ancount = 867
nscount = 28525
arcount = 0
qd = ''
an = ''
ns = ''
ar = None
###[ Raw ]###
load = '\x01\x00\x01\xc0\x0c\x00\x01\x00\x01\x00\x00\x00<\x00\x04\x80w\xf3\x86'
05:66:61:6c:75:6e:03:63:6f:6d:00:00:01:00:01:c0:0c:00:01:00:01:00:00:00:3c:00:04:80:77:f3:86