3 Commits

Author SHA1 Message Date
51e3d252f2 Add color mode to dnseval ("-C" option) 2017-04-26 12:53:05 +04:30
7db7684c95 Fix display in case of no answer (fix #34) 2017-04-25 22:28:22 +04:30
bde3263cfa Use semantic versioning
and more standard constant names
2017-04-24 17:43:47 +04:30
3 changed files with 50 additions and 20 deletions

View File

@ -38,15 +38,33 @@ from statistics import stdev
import dns.rdatatype import dns.rdatatype
import dns.resolver import dns.resolver
__VERSION__ = 1.6 __author__ = 'Babak Farrokhi (babak@farrokhi.net)'
__PROGNAME__ = os.path.basename(sys.argv[0]) __license__ = 'BSD'
__version__ = "1.6.0"
__progname__ = os.path.basename(sys.argv[0])
shutdown = False shutdown = False
resolvers = dns.resolver.get_default_resolver().nameservers resolvers = dns.resolver.get_default_resolver().nameservers
class Colors(object):
N = '\033[m' # native
R = '\033[31m' # red
G = '\033[32m' # green
O = '\033[33m' # orange
B = '\033[34m' # blue
def __init__(self, mode):
if not mode:
self.N = ''
self.R = ''
self.G = ''
self.O = ''
self.B = ''
def usage(): def usage():
print("""%s version %1.1f print("""%s version %s
usage: %s [-h] [-f server-list] [-c count] [-t type] [-w wait] hostname usage: %s [-h] [-f server-list] [-c count] [-t type] [-w wait] hostname
-h --help show this help -h --help show this help
@ -56,8 +74,9 @@ usage: %s [-h] [-f server-list] [-c count] [-t type] [-w wait] hostname
-t --type DNS request record type (default: A) -t --type DNS request record type (default: A)
-T --tcp Use TCP instead of UDP -T --tcp Use TCP instead of UDP
-e --edns Disable EDNS0 (Default: Enabled) -e --edns Disable EDNS0 (Default: Enabled)
-C --color Print colorful output
-v --verbose Print actual dns response -v --verbose Print actual dns response
""" % (__PROGNAME__, __VERSION__, __PROGNAME__)) """ % (__progname__, __version__, __progname__))
sys.exit() sys.exit()
@ -194,11 +213,12 @@ def main():
use_tcp = False use_tcp = False
use_edns = True use_edns = True
verbose = False verbose = False
color_mode = False
hostname = 'wikipedia.org' hostname = 'wikipedia.org'
try: try:
opts, args = getopt.getopt(sys.argv[1:], "hf:c:t:w:Tev", opts, args = getopt.getopt(sys.argv[1:], "hf:c:t:w:TevC",
["help", "file=", "count=", "type=", "wait=", "tcp", "edns", "verbose"]) ["help", "file=", "count=", "type=", "wait=", "tcp", "edns", "verbose", "color"])
except getopt.GetoptError as err: except getopt.GetoptError as err:
print(err) print(err)
usage() usage()
@ -224,12 +244,16 @@ def main():
use_tcp = True use_tcp = True
elif o in ("-e", "--edns"): elif o in ("-e", "--edns"):
use_edns = False use_edns = False
elif o in ("-C", "--color"):
color_mode = True
elif o in ("-v", "--verbose"): elif o in ("-v", "--verbose"):
verbose = True verbose = True
else: else:
print("Invalid option: %s" % o) print("Invalid option: %s" % o)
usage() usage()
color = Colors(color_mode)
try: try:
if fromfile: if fromfile:
with open(inputfilename, 'rt') as flist: with open(inputfilename, 'rt') as flist:
@ -286,12 +310,16 @@ def main():
if s_ttl == "None": if s_ttl == "None":
s_ttl = "N/A" s_ttl = "N/A"
print("%s %-8.3f %-8.3f %-8.3f %-8.3f %%%-3d %-8s %21s" % ( if r_lost_percent > 0:
s, r_avg, r_min, r_max, r_stddev, r_lost_percent, s_ttl, text_flags), flush=True) l_color = color.O
if verbose: else:
l_color = color.N
print("%s %-8.3f %-8.3f %-8.3f %-8.3f %s%%%-3d%s %-8s %21s" % (
s, r_avg, r_min, r_max, r_stddev, l_color, r_lost_percent, color.N, s_ttl, text_flags), flush=True)
if verbose and hasattr(answers, 'response'):
ans_index = 1 ans_index = 1
for answer in answers.response.answer: for answer in answers.response.answer:
print("Answer %d [ %s ]" % (ans_index, answer)) print("Answer %d [ %s%s%s ]" % (ans_index, color.B, answer, color.N))
ans_index += 1 ans_index += 1
print("") print("")

View File

@ -38,13 +38,15 @@ import dns.flags
import dns.rdatatype import dns.rdatatype
import dns.resolver import dns.resolver
__VERSION__ = 1.6 __author__ = 'Babak Farrokhi (babak@farrokhi.net)'
__PROGNAME__ = os.path.basename(sys.argv[0]) __license__ = 'BSD'
__version__ = "1.6.0"
__progname__ = os.path.basename(sys.argv[0])
shutdown = False shutdown = False
def usage(): def usage():
print("""%s version %1.1f print("""%s version %s
usage: %s [-ehqv] [-s server] [-p port] [-P port] [-S address] [-c count] [-t type] [-w wait] hostname usage: %s [-ehqv] [-s server] [-p port] [-P port] [-S address] [-c count] [-t type] [-w wait] hostname
-h --help Show this help -h --help Show this help
-q --quiet Quiet -q --quiet Quiet
@ -61,7 +63,7 @@ usage: %s [-ehqv] [-s server] [-p port] [-P port] [-S address] [-c count] [-t ty
-i --interval Time between each request (default: 0 seconds) -i --interval Time between each request (default: 0 seconds)
-t --type DNS request record type (default: A) -t --type DNS request record type (default: A)
-e --edns Disable EDNS0 (default: Enabled) -e --edns Disable EDNS0 (default: Enabled)
""" % (__PROGNAME__, __VERSION__, __PROGNAME__)) """ % (__progname__, __version__, __progname__))
sys.exit(0) sys.exit(0)
@ -172,7 +174,7 @@ def main():
response_time = [] response_time = []
i = 0 i = 0
print("%s DNS: %s:%d, hostname: %s, rdatatype: %s" % (__PROGNAME__, dnsserver, dst_port, hostname, dnsrecord)) print("%s DNS: %s:%d, hostname: %s, rdatatype: %s" % (__progname__, dnsserver, dst_port, hostname, dnsrecord))
for i in range(count): for i in range(count):
if shutdown: if shutdown:

View File

@ -43,7 +43,7 @@ from cymruwhois import cymruwhois
__author__ = 'Babak Farrokhi (babak@farrokhi.net)' __author__ = 'Babak Farrokhi (babak@farrokhi.net)'
__license__ = 'BSD' __license__ = 'BSD'
__version__ = 1.6 __version__ = "1.6.0"
_ttl = None _ttl = None
quiet = False quiet = False
@ -65,7 +65,7 @@ def test_import():
# Constants # Constants
__PROGNAME__ = os.path.basename(sys.argv[0]) __progname__ = os.path.basename(sys.argv[0])
WHOIS_CACHE = 'whois.cache' WHOIS_CACHE = 'whois.cache'
@ -117,8 +117,8 @@ except IOError:
def usage(): def usage():
print('%s version %1.1f\n' % (__PROGNAME__, __version__)) print('%s version %s\n' % (__progname__, __version__))
print('usage: %s [-aeqhCx] [-s server] [-p port] [-c count] [-t type] [-w wait] hostname' % __PROGNAME__) print('usage: %s [-aeqhCx] [-s server] [-p port] [-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(' -x --expert Print expert hints if available') print(' -x --expert Print expert hints if available')
@ -303,7 +303,7 @@ def main():
trace_path = [] trace_path = []
if not quiet: if not quiet:
print("%s DNS: %s:%d, hostname: %s, rdatatype: %s" % (__PROGNAME__, dnsserver, dest_port, hostname, dnsrecord), print("%s DNS: %s:%d, hostname: %s, rdatatype: %s" % (__progname__, dnsserver, dest_port, hostname, dnsrecord),
flush=True) flush=True)
while True: while True: