Skip to content

Commit

Permalink
catch nameserver lookup errors. ipv6 support. switch to non-negative …
Browse files Browse the repository at this point in the history
…exit codes on error
  • Loading branch information
joemiller committed Aug 6, 2013
1 parent e4aad86 commit 4ca3589
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions dns_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
except ImportError:
print "Please install dnspython:"
print "$ sudo pip install dnspython"
sys.exit(-1)
sys.exit(1)


if __name__ == '__main__':
Expand All @@ -67,12 +67,16 @@
# check for required options, since optparse doesn't support required options
if opts.zone == None or opts.zonefile == None or opts.nameserver == None:
print "Error: required arguments: --zone, --file, --server (or --help)"
sys.exit(-1)
sys.exit(2)

z = dns.zone.from_file(opts.zonefile, origin=opts.zone, relativize=False)

r = dns.resolver.Resolver(configure=False)
r.nameservers = [socket.gethostbyname(opts.nameserver)]
try:
r.nameservers = socket.gethostbyname_ex(opts.nameserver)[2]
except socket.error:
print "Error: could not resolve 'host' %s" % opts.nameserver
sys.exit(3)

matches=0
mismatches=0
Expand Down

0 comments on commit 4ca3589

Please sign in to comment.