Skip to content

Instantly share code, notes, and snippets.

@fxlv
Created January 8, 2015 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fxlv/22490abba76b60684aae to your computer and use it in GitHub Desktop.
Save fxlv/22490abba76b60684aae to your computer and use it in GitHub Desktop.
#!/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