DNS

#!python
#!/usr/bin/python
 
import sys
from re import compile
from DNS import Request
 
in_file = open(sys.argv[1])
 
ipRegEx = compile('\d+\.\d+\.\d+\.\d+')
urls = '''heise.de google.com uni-freiburg.de markusdobler.de
          youtube.com imtek.de reddit.com stackoverflow.com
          spiegel.de debian.org amazon.ca'''.split()
 
working_servers = {}
failing_servers = {}
 
def fail(ip, msg):
    print "%s: %s" % (ip, msg)
    failing_servers[ip] = msg
 
for line in in_file:
    try:
        ip = ipRegEx.search(line).group(0)
    except AttributeError:
        continue
 
    try:
        # is the dns server reporting bogus data for non-existing domains?
        # (forwards to 'helpful' portal of the provider)
        response = Request(name='www.unkno.wn', server=ip, qtype='A').req()
        if response.answers:
            raise Exception("resolved www.unkno.wn")
 
        # is the dns server vulnerable to cache poisoning?
        response = Request(name='porttest.dns-oarc.net', server=ip,
                qtype='txt').req()
        s = str(response.answers)
        if "GREAT" not in s and "GOOD" not in s:
            raise Exception("potentially vulnerable to cache poisoning")
 
        total_time = response.args['elapsed']/10 # reduce impact of this query
 
        # query several domains
        for url in urls:
            response = Request(name=url, server=ip, qtype='A').req()
            total_time += response.args['elapsed']
            ips = [a['data'] for a in response.answers]
            if not ips:
                raise Exception("couldn't resolve %s" % url)
        else:
            working_servers[ip] = total_time
            print "nameserver %s needed %.1f ms" % (ip, total_time)
    except Exception, e:
        fail(ip, e)
 
 
try:
    out_file = open(sys.argv[2], 'w')
except:
    out_file = sys.stdout
 
for time, ip in sorted((time, ip) for (ip, time) in working_servers.items()):
    out_file.write("  * %s: %.1f ms\n" % (ip, time))
 
out_file.write("\n")
 
for ip, msg in failing_servers.items():
    out_file.write("  * %s: %s\n" % (ip, msg))
  • 212.82.226.212: 150.1 ms
  • 213.157.0.194: 681.5 ms
  • 217.9.17.34: 686.4 ms
  • 141.1.1.1: 686.8 ms
  • 212.9.160.1: 754.2 ms
  • 131.188.3.2: 830.7 ms
  • 193.101.111.20: 831.6 ms
  • 212.82.225.7: 837.2 ms
  • 145.253.2.75: 844.1 ms
  • 4.2.2.4: 861.5 ms
  • 213.157.0.193: 888.5 ms
  • 193.101.111.10: 903.6 ms
  • 195.202.33.68: 935.0 ms
  • 192.76.144.66: 939.0 ms
  • 145.253.2.11: 940.9 ms
  • 212.114.153.1: 960.8 ms
  • 4.2.2.2: 1023.4 ms
  • 4.2.2.1: 1032.2 ms
  • 212.118.160.1: 1052.5 ms
  • 195.202.32.79: 1054.1 ms
  • 194.24.128.102: 1059.2 ms
  • 83.142.86.1: 1096.5 ms
  • 145.253.2.203: 1112.6 ms
  • 62.72.64.237: 1189.2 ms
  • 130.149.4.20: 1223.7 ms
  • 4.2.2.3: 1246.5 ms
  • 4.2.2.5: 1252.1 ms
  • 62.72.64.241: 1261.7 ms
  • 212.7.148.65: 1270.5 ms
  • 212.7.148.97: 1332.0 ms
  • 4.2.2.6: 1347.4 ms
  • 85.214.73.63: 1391.9 ms
  • 217.9.16.14: 1524.4 ms
  • 194.150.168.168: 1676.0 ms
  • 204.152.184.76: 2709.8 ms
  • 212.114.152.1: 2772.1 ms
  • 213.144.129.2: 2854.8 ms
  • 212.110.122.132: 4009.9 ms
  • 165.76.16.2: 5576.1 ms
  • 212.55.195.90: 7131.7 ms
  • 213.191.74.18: resolved www.unkno.wn
  • 212.88.160.2: Timeout
  • 217.237.151.142: potentially vulnerable to cache poisoning
  • 212.63.128.212: potentially vulnerable to cache poisoning
  • 212.88.160.5: Timeout
  • 217.237.148.70: potentially vulnerable to cache poisoning
  • 217.237.150.188: potentially vulnerable to cache poisoning
  • 134.100.9.61: potentially vulnerable to cache poisoning
  • 193.158.124.58: potentially vulnerable to cache poisoning
  • 217.237.149.142: potentially vulnerable to cache poisoning
  • 217.237.148.102: potentially vulnerable to cache poisoning
  • 217.237.150.115: potentially vulnerable to cache poisoning
  • 213.191.74.19: resolved www.unkno.wn
  • 195.85.254.254: Timeout
  • 134.100.33.240: potentially vulnerable to cache poisoning
  • 131.188.3.4: no working nameservers found
  • 217.237.151.115: potentially vulnerable to cache poisoning
  • 212.95.97.66: potentially vulnerable to cache poisoning
  • 217.237.149.205: potentially vulnerable to cache poisoning
  • 194.25.2.129: Timeout
  • computer/dns.txt
  • Last modified: 2020-10-29 22:13
  • by 127.0.0.1