Monday, May 05, 2014

Fast DNS Resolver

I called this "Fast DNS Resolver" not because it is fast (at execution). It is because it is short, and simply resolve the IP address (including reverse DNS) for a list FQDN for me (fast).

(If you are looking for really fast execution python script to resolve DNS, try this Asynchronous DNS Resolution)

import os, sys, socket, argparse
name = ""
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Fast DNS Resolver for domain list', version='%(prog)s 1.0')
    parser.add_argument('-R', dest='rdns', action='store_true', default=False, help='reverse dns')
    parser.add_argument('infile', nargs='+', type=str, help='list of input files')
    args = parser.parse_args()
    domains = []
    for f in args.infile:
        with open(f, 'rt') as data:
            for line in data.readlines():
    for domain in domains:
            host =  socket.gethostbyname(domain)
        except Exception, e:
            host = "-"
            if args.rdns:
                    name, alias, addresslist = socket.gethostbyaddr(host)
                except Exception, e:
                    name = "-" # reverse dns name
                print "%s:%s:%s" %(domain, host, name)
                print "%s:%s" % (domain, host)