40 likes | 155 Views
Network Programming Kansas State University at Salina. Domain Name System (DNS) Topic 2, Chapter 4. DNS. Host name to IP address look up and reverse Hierarchical, distributed, cached database Many services provided by OS sock.connect( (hostname, port) ) socket.getaddrinfo( hostname, None ).
E N D
Network Programming Kansas State University at Salina Domain Name System (DNS) Topic 2, Chapter 4
DNS • Host name to IP address look up and reverse • Hierarchical, distributed, cached database • Many services provided by OS • sock.connect( (hostname, port) ) • socket.getaddrinfo( hostname, None )
Advanced DNS – DNSPython • Lookup of MX records for sending e-mail is one example where you might need to program a DNS lookup. • Need to add additional package for stand alone DNS lookups. • Book discusses PyDNS, available from source forge. • The package index on python.org suggests that DNSPython is a more popular DNS package.
DNSPython • http://www.dnspython.org/ • Also available from K-State Online • Get the MX targets and preferences for a domain: import dns.resolver answers = dns.resolver.query(‘gmail.com', 'MX') for rdata in answers: print 'Host', rdata.exchange, 'has preference', rdata.preference