use internal list of DNS servers as default

and other minor cleanups
This commit is contained in:
Babak Farrokhi 2016-02-10 09:23:06 +03:30
parent eaf9323bd7
commit eddbc8a5b1
3 changed files with 27 additions and 23 deletions

View File

@ -1,9 +0,0 @@
4.2.2.1
4.2.2.2
64.6.64.6
64.6.65.6
8.8.4.4
8.8.8.8
208.67.222.222
208.67.220.220

View File

@ -26,10 +26,10 @@
import getopt import getopt
import signal
import sys
import time import time
from statistics import stdev from statistics import stdev
import sys
import signal
import dns.rdatatype import dns.rdatatype
import dns.resolver import dns.resolver
@ -37,16 +37,26 @@ import dns.resolver
__VERSION__ = 1.0 __VERSION__ = 1.0
should_stop = False should_stop = False
resolvers = [
'4.2.2.1',
'4.2.2.2',
'64.6.64.6',
'64.6.65.6',
'8.8.4.4',
'8.8.8.8',
'208.67.222.222',
'208.67.220.220'
]
def usage(): def usage():
print('dnsperf version %1.1f\n' % __VERSION__) print('dnsperf version %1.1f\n' % __VERSION__)
print('syntax: dnsping [-h] [-f server-list] [-c count] [-t type] [-w wait] hostname') print('syntax: dnsping [-h] [-f server-list] [-c count] [-t type] [-w wait] hostname')
print(' -h --help show this help') print(' -h --help show this help')
print(' -f --file dns server to use (default: dnsperf.list)') print(' -f --file dns server list to use')
print(' -c --count number of requests to send (default: 10)') print(' -c --count number of requests to send (default: 10)')
print(' -w --wait maximum wait time for a reply (default: 5)') print(' -w --wait maximum wait time for a reply (default: 5)')
print(' -t --type DNS request record type (default: A)') print(' -t --type DNS request record type (default: A)')
print(' ')
exit() exit()
@ -99,13 +109,9 @@ def dnsping(host, server, dnsrecord, timeout, count):
r_avg = 0 r_avg = 0
r_stddev = 0 r_stddev = 0
# print("%-15s avg: %-8.3f ms min: %-8.3f ms max: %-8.3f stddev: %-8.3f lost: %%%d" % (
# server, r_avg, r_min, r_max, r_stddev, r_lost_percent))
print("%-15s %-8.3f %-8.3f %-8.3f %-8.3f %%%d" % ( print("%-15s %-8.3f %-8.3f %-8.3f %-8.3f %%%d" % (
server, r_avg, r_min, r_max, r_stddev, r_lost_percent)) server, r_avg, r_min, r_max, r_stddev, r_lost_percent))
# return r_min, r_max, r_avg, r_lost_percent, r_stddev
def main(): def main():
signal.signal(signal.SIGTSTP, signal.SIG_IGN) # ignore CTRL+Z signal.signal(signal.SIGTSTP, signal.SIG_IGN) # ignore CTRL+Z
@ -117,7 +123,8 @@ def main():
dnsrecord = 'A' dnsrecord = 'A'
count = 10 count = 10
waittime = 5 waittime = 5
inputfile = 'dnsperf.list' inputfilename = None
fromfile = False
hostname = 'wikipedia.org' hostname = 'wikipedia.org'
try: try:
@ -138,16 +145,21 @@ def main():
elif o in ("-c", "--count"): elif o in ("-c", "--count"):
count = int(a) count = int(a)
elif o in ("-f", "--file"): elif o in ("-f", "--file"):
inputfile = a inputfilename = a
fromfile = True
elif o in ("-w", "--wait"): elif o in ("-w", "--wait"):
waittime = int(a) waittime = int(a)
elif o in ("-t", "--type"): elif o in ("-t", "--type"):
dnsrecord = a dnsrecord = a
else: else:
print("Invalid option: %s" % o)
usage() usage()
try: try:
f = open(inputfile, 'rt') if fromfile:
f = open(inputfilename, 'rt')
else:
f = resolvers
print('server avg(ms) min(ms) max(ms) stddev(ms) lost(%)') print('server avg(ms) min(ms) max(ms) stddev(ms) lost(%)')
print('--------------------------------------------------------------------------') print('--------------------------------------------------------------------------')
for server in f: for server in f:
@ -155,7 +167,8 @@ def main():
if not s: if not s:
continue continue
dnsping(hostname, s, dnsrecord, waittime, count) dnsping(hostname, s, dnsrecord, waittime, count)
f.close() if fromfile:
f.close()
except Exception as e: except Exception as e:
print('error: %s' % e) print('error: %s' % e)
exit(1) exit(1)

View File

@ -26,10 +26,10 @@
import getopt import getopt
import signal
import sys
import time import time
from statistics import stdev from statistics import stdev
import sys
import signal
import dns.rdatatype import dns.rdatatype
import dns.resolver import dns.resolver