python - Human readable form of DNS lookup -


i have got simple idea in mind want try out. have browser, chrome instance, , want search ip of domain name, www.google.com. use windows 7 , have set dns lookup properties manual , have given address 127.0.0.1 server (written in python running). started server , see dns query weird in showing faces this:

waiting connection.........  .........recieved :  ('127.0.0.1', 59339)  'v"\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x06teredo\x04ipv6\tmicrosoft\x03com\x00\x00\x01\x00\x01' 

the waiting connection , received from server. how breakdown form(a human readable form) of message??

this server code(quiet elementary still):

here code:

from time import sleep  import socket  host=''  port=53  addr_list=(host,port)  buf_siz=1024  udp=socket.socket(socket.af_inet,socket.sock_dgram)  udp.bind(addr_list)  while true:      print 'waiting connection.........'      data,addr = udp.recvfrom(buf_siz) print '.........recieved : ',addr      sleep(3)      print data 

if want analyse query data using python, recommend excellent scapy library (http://www.secdev.org/projects/scapy/) it's got decoding (and building!) routines many network protocols including dns.

here's original program scapy decoding added:

from time import sleep import socket scapy.all import dns #bring in scapy's dns decoder  host='' port=53 addr_list=(host,port) buf_siz=1024 udp=socket.socket(socket.af_inet,socket.sock_dgram) udp.bind(addr_list) while true:     print 'waiting connection.........'     data,addr = udp.recvfrom(buf_siz) print '.........recieved : ',addr     sleep(3)     #decode dns data     decoded = dns(data)     #print decoded packet     decoded.show() 

for raw packet in question prints:

###[ dns ]###   id        = 22050   qr        = 0l   opcode    = query   aa        = 0l   tc        = 0l   rd        = 1l   ra        = 0l   z         = 0l   rcode     = ok   qdcount   = 1   ancount   = 0   nscount   = 0   arcount   = 0   \qd        \    |###[ dns question record ]###    |  qname     = 'teredo.ipv6.microsoft.com.'    |  qtype     = 12288    |  qclass    = 256          = none   ns        = none   ar        = none ###[ raw ]###      load      = '\x01' 

scapy installation instructions here: http://www.secdev.org/projects/scapy/doc/installation.html#installing-scapy-v2-x

if use ubuntu, sudo apt-get install python-scapy

enjoy!


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

c# - SharpSVN - How to get the previous revision? -

php cli reading files and how to fix it? -