Simple time saving dns info script
Simple dns info script which tells the user the nameservers, MX records, and attempts zone transfers on all nameservers. Check it out.
Click here to view and download the script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #!/usr/bin/python # a script that uses the host command to lookup various dns information of a target # coded by: bostonlink import sys,subprocess usage = """\ndns_script.py coded by bostonlink @ pentestlabs.org\n Usage: ./dns_script.py domainname Example: ./dns_script.py google.com\n""" if len(sys.argv) != 2: print(usage) sys.exit(0) target = sys.argv[1] print("\n" + "*" * 60) print("%s nameservers" % sys.argv[1]) print("*" * 60 + "\n") pro1 = subprocess.Popen(["host","-t","ns",target], stdout=subprocess.PIPE) ns = pro1.stdout.read() pro1.wait() print(ns) print("\n" + "*" * 60) print("%s mailservers" % sys.argv[1]) print("*" * 60 + "\n") pro2 = subprocess.Popen(["host","-t","mx",target], stdout=subprocess.PIPE) mx = pro2.stdout.read() pro2.wait() print(mx) ns_list = ns.strip().split() for nameserver in ns_list: if nameserver.endswith("."): zone_tr = nameserver.rstrip(".") print("\n" + "*" * 60) print("%s zone transfer against %s" % (sys.argv[1],zone_tr)) print("*" * 60 + "\n") pro3 = subprocess.Popen(["host","-l",target,zone_tr], stdout=subprocess.PIPE) ztrans = pro3.stdout.read() pro3.wait() print(ztrans) else: continue print("\nScript completed") |
Example:
root@bt:~/my stuff/scripts/python_dev# ./dns_script_2.py google.com
************************************************************
google.com nameservers
************************************************************
google.com name server ns1.google.com.
google.com name server ns2.google.com.
google.com name server ns4.google.com.
google.com name server ns3.google.com.
************************************************************
google.com mailservers
************************************************************
google.com mail is handled by 200 google.com.s9a2.psmtp.com.
google.com mail is handled by 100 google.com.s9a1.psmtp.com.
google.com mail is handled by 300 google.com.s9b1.psmtp.com.
google.com mail is handled by 400 google.com.s9b2.psmtp.com.
************************************************************
google.com zone transfer against ns1.google.com
************************************************************
; Transfer failed.
Using domain server:
Name: ns1.google.com
Address: 216.239.32.10#53
Aliases:
Host google.com.localdomain not found: 5(REFUSED)
; Transfer failed.
************************************************************
google.com zone transfer against ns2.google.com
************************************************************
snip……….
-bostonlink


