Created
January 8, 2015 19:18
-
-
Save fxlv/22490abba76b60684aae to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import sys | |
# default dns query timeout is 5 seconds | |
retrans = 5 | |
# give the user a chance to override it by passing an argument | |
if (len(sys.argv) == 2): | |
retrans = int(sys.argv[1]) | |
# 3 dummy IP addresses | |
nameservers = ["1.1.1.1", "2.2.2.2", "3.3.3.3"] | |
# nscount is the count of nameservers | |
nscount = len(nameservers) | |
# lets loop over them all and replicate the logic found in res_send.c | |
for nameserver in nameservers: | |
ns = nameservers.index(nameserver) | |
seconds = ( retrans << ns ) | |
if (ns > 0): | |
seconds = seconds / nscount | |
if (seconds <= 0): | |
seconds = 1 | |
# and for visibility we print it out | |
print "Nameserver # {} has timeout {}".format(ns,seconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment