#! /usr/bin/env python # dnslook 0.11 # 03 Apr 2001 # =========== # # CONTRIVANCE # # =========== # # # great-auk.example.com <-> 10.1.2.3 # eudaemon.example.com <-> 10.9.9.9, 10.8.8.8, 10.7.7.7 # vacant.example.com <-> NXDOMAIN import os from dnslook import * # --------------- # Address Lookups # --------------- ip = "10.1.2.3" try: # c.f. socket.gethostbyaddr() dn = name4(ip) # except error: # except dnslook.error, e: dn = None # if e[0] == errno.EAGAIN: mere_serv_fail() # if e[0] == errno.EIO: bad_error() print dn # "great-auk.example.com" # ----------------------- # Names and Qualification # ----------------------- print dnslook.ip4("great-auk.example.com") # '10.1.2.3' print dnslook.ip4("vacant.example.com") # None os.environ['LOCALDOMAIN'] = "example.com" # otherwise use /etc/resolv.conf domain or search line print dnslook.ip4_qualify("eudaemon") # ('eudaemon.example.com', ('10.9.9.9', '10.8.8.8', '10.7.7.7')) print dnslook.ip4_qualify("vacant") # ('vacant.example.com', ()) # ---------- # MX Records # ---------- print dnslook.mx("example.com") # ((10, 'mail1.example.com'), (20, 'mail2.example.com')) # ----- # Other # ----- print dnslook.txt("example.com") # 'Ooh, a TXT record' print dnslook.ns("example.com") # probably ('a.ns.example.com', 'b.ns.example.com')