use system resolver instead of hardcoded list (resolve #6)

This commit is contained in:
Babak Farrokhi 2016-04-10 16:02:23 +04:30
parent c2709fd1bf
commit b0b3426b0f
Signed by: farrokhi
GPG Key ID: 6B267AD85D632E9A
2 changed files with 9 additions and 18 deletions

View File

@ -38,23 +38,14 @@ __VERSION__ = 1.0
__PROGNAME__ = os.path.basename(sys.argv[0]) __PROGNAME__ = os.path.basename(sys.argv[0])
should_stop = False should_stop = False
resolvers = [ resolvers = dns.resolver.get_default_resolver().nameservers
'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('%s version %1.1f\n' % (__PROGNAME__, __VERSION__)) print('%s version %1.1f\n' % (__PROGNAME__, __VERSION__))
print('syntax: %s [-h] [-f server-list] [-c count] [-t type] [-w wait] hostname' % __PROGNAME__) print('syntax: %s [-h] [-f server-list] [-c count] [-t type] [-w wait] hostname' % __PROGNAME__)
print(' -h --help show this help') print(' -h --help show this help')
print(' -f --file dns server list to use') print(' -f --file dns server list to use (default: system resolvers)')
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)')
@ -69,7 +60,7 @@ def signal_handler(sig, frame):
def widest_len(names): def widest_len(names):
width = 0 width = 8
for s in names: for s in names:
if len(s) > width: if len(s) > width:
width = len(s) width = len(s)
@ -169,6 +160,8 @@ def main():
f = flist.read().splitlines() f = flist.read().splitlines()
else: else:
f = resolvers f = resolvers
if len(f) == 0:
print("No nameserver specified")
width = widest_len(f) width = widest_len(f)
blanks = (width - 5) * ' ' blanks = (width - 5) * ' '
print('server ', blanks, ' avg(ms) min(ms) max(ms) stddev(ms) lost(%)') print('server ', blanks, ' avg(ms) min(ms) max(ms) stddev(ms) lost(%)')

View File

@ -25,6 +25,8 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import dns.rdatatype
import dns.resolver
import getopt import getopt
import os import os
import signal import signal
@ -32,9 +34,6 @@ import socket
import sys import sys
import time import time
import dns.rdatatype
import dns.resolver
__VERSION__ = 1.0 __VERSION__ = 1.0
__PROGNAME__ = os.path.basename(sys.argv[0]) __PROGNAME__ = os.path.basename(sys.argv[0])
should_stop = False should_stop = False
@ -45,7 +44,7 @@ def usage():
print('syntax: %s [-h] [-q] [-s server] [-c count] [-t type] [-w wait] hostname' % __PROGNAME__) print('syntax: %s [-h] [-q] [-s server] [-c count] [-t type] [-w wait] hostname' % __PROGNAME__)
print(' -h --help show this help') print(' -h --help show this help')
print(' -q --quiet quiet') print(' -q --quiet quiet')
print(' -s --server dns server to use (default: 8.8.8.8)') print(' -s --server dns server to use (default: first system resolver)')
print(' -c --count maximum number of hops (default: 30)') print(' -c --count maximum number of hops (default: 30)')
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)')
@ -71,8 +70,7 @@ def main():
count = 30 count = 30
timeout = 1 timeout = 1
quiet = False quiet = False
dnsserver = '8.8.8.8' dnsserver = dns.resolver.get_default_resolver().nameservers[0]
hostname = 'wikipedia.org'
dnsport = 53 dnsport = 53
hops = 0 hops = 0