Add exception handling to getA and getAAAA
authorPieter Lexis <pieter.lexis@os3.nl>
Thu, 26 Jan 2012 13:56:19 +0000 (14:56 +0100)
committerPieter Lexis <pieter.lexis@os3.nl>
Thu, 26 Jan 2012 13:56:19 +0000 (14:56 +0100)
  * Basically, exit if no records can be found.
  * For AAAA it doesnt matter anyway, as it isn't used (yet?)

swede

diff --git a/swede b/swede
index 2ebaf9bbe4d721e25b0a4d3260edb22f2ad156f2..861211e85b9834b674f487bcd53c2e3d8efd27d5 100755 (executable)
--- 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)))))