-
-
Save hkraal/345e488f6b555efcb4bb to your computer and use it in GitHub Desktop.
Python script which illustrates a timeout quering a specific nameserver for the NS records of a domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
Github issue opened by me: https://github.com/rthalley/dnspython/issues/45 | |
This module is an example which creates an dns.exception.Timeout Exception on | |
line 43 while tpcdump shows that an answer is returned each loop in | |
/usr/lib/python2.7/dist-packages/dns/resolver.py | |
"tcpdump -nS host 194.0.1.19 -A" from this script: | |
10:02:43.870020 IP 10.0.3.250.56714 > 194.0.1.19.53: 47557+ NS? server.eu. (27) | |
E..7..@.@.i. | |
..........5.#.Q.............server.eu..... | |
10:02:44.037592 IP 194.0.1.19.53 > 10.0.3.250.56714: 47557- 0/3/4 (179) | |
E.....@.8.q..... | |
....5....x?.............server.eu.............Q....ns1..........Q....ns2..........Q....ns.coredns.org..'......Q...M_...'......Q...*..x. .....r.....9......Q...Uw...9......Q...*..`............ | |
"tcpdump -nS host 194.0.1.19 -A" from the dig command: | |
10:04:33.541576 IP 10.0.3.250.41266 > 194.0.1.19.53: 34813+ NS? server.eu. (27) | |
E..7.f..@..C | |
........2.5.#Gr.............server.eu..... | |
10:04:33.707040 IP 194.0.1.19.53 > 10.0.3.250.41266: 34813- 0/3/4 (179) | |
E.....@.7.r..... | |
....5.2..._.............server.eu.............Q....ns1..........Q....ns2..........Q....ns.coredns.org..'......Q...M_...'......Q...*..x. .....r.....9......Q...Uw...9......Q...*..`............ | |
''' | |
import dns.resolver | |
if __name__ == '__main__': | |
# Get the nameservers for our TLD | |
tldnameservers = dns.resolver.query('eu', 'NS') | |
# Walk trough the nameservers for our TLD | |
for tldnameserver in tldnameservers: | |
theNameserver = tldnameserver.to_text() | |
print "going for %s" % theNameserver | |
resolver = dns.resolver.Resolver() | |
resolver.nameservers = [theNameserver] | |
# Print the dig-like command | |
print "dig -4 ns server.eu @%s" % (theNameserver) | |
# Fire DNS query | |
tldNameserverRecords = resolver.query('server.eu', 'NS') | |
# Walk trough our results | |
for tldNameserverRecord in tldNameserverRecords: | |
print "Result: %s" % tldNameserverRecord | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment