From c7a602ae4e43a0d75fd722d34b91fa26bdc29aa4 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Mon, 16 May 2016 14:17:39 +0430 Subject: [PATCH] deal with empty lines in input file (fix #15) --- dnseval.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dnseval.py b/dnseval.py index f472eea..b3b0930 100755 --- a/dnseval.py +++ b/dnseval.py @@ -34,9 +34,9 @@ import sys import time from statistics import stdev +import dns.flags import dns.rdatatype import dns.resolver -import dns.flags __VERSION__ = 1.0 __PROGNAME__ = os.path.basename(sys.argv[0]) @@ -179,6 +179,9 @@ def main(): print((70 + width) * '-') for server in f: # check if we have a valid dns server address + if server.lstrip() == '': # deal with empty lines + continue + try: ipaddress.ip_address(server) except ValueError: # so it is not a valid IPv4 or IPv6 address, so try to resolve host name @@ -193,7 +196,7 @@ def main(): if not s: continue (s, r_avg, r_min, r_max, r_stddev, r_lost_percent, flags) = dnsping(hostname, s, dnsrecord, waittime, - count) + count) s = server.ljust(width + 1) print("%s %-8.3f %-8.3f %-8.3f %-8.3f %%%d %13s" % (