From: Pieter Lexis Date: Thu, 26 Jan 2012 13:56:19 +0000 (+0100) Subject: Add exception handling to getA and getAAAA X-Git-Url: https://git.svenne.dk/?p=public%2Fdnssec-swede-utility.git;a=commitdiff_plain;h=6bc17355f735d67bd6453d5cc547cf049a5cb2af Add exception handling to getA and getAAAA * Basically, exit if no records can be found. * For AAAA it doesnt matter anyway, as it isn't used (yet?) --- diff --git a/swede b/swede index 2ebaf9b..861211e 100755 --- a/swede +++ b/swede @@ -59,7 +59,14 @@ def genTLSA(hostname, protocol, port, certificate, output='draft', usage=1, sele def getA(hostname, secure=True): """Gets a list of A records for hostname, returns a list of ARecords""" - records = getRecords(hostname, rrtype='A', secure=secure) + try: + records = getRecords(hostname, rrtype='A', secure=secure) + except InsecureLookupException, e: + print str(e) + sys.exit(1) + except DNSLookupError, e: + print 'Unable to resolve %s: %s' % (hostname, str(e)) + sys.exit(1) ret = [] for record in records: ret.append(ARecord(hostname, str(IPv4Address(int(b2a_hex(record),16))))) @@ -67,7 +74,14 @@ def getA(hostname, secure=True): def getAAAA(hostname, secure=True): """Gets a list of A records for hostname, returns a list of AAAARecords""" - records = getRecords(hostname, rrtype='AAAA', secure=secure) + try: + records = getRecords(hostname, rrtype='AAAA', secure=secure) + except InsecureLookupException, e: + print str(e) + sys.exit(1) + except DNSLookupError, e: + print 'Unable to resolve %s: %s' % (hostname, str(e)) + sys.exit(1) ret = [] for record in records: ret.append(AAAARecord(hostname, str(IPv6Address(int(b2a_hex(record),16)))))