'The function for retrieving ASN information for an IP address from
Cymru via port 53 (DNS).
Args:
result: Optional result object. This bypasses the ASN lookup.
Returns:
Dictionary: A dictionary containing the following keys:
asn (String) - The Autonomous System Number.
asn_date (String) - The ASN Allocation date.
asn_registry (String) - The assigned ASN registry.
asn_cidr (String) - The assigned ASN CIDR.
asn_country_code (String) - The assigned ASN country code.
Raises:
ASNRegistryError: The ASN registry is not known.
ASNLookupError: The ASN lookup failed.'

def get_asn_dns(self, result=None):

    try:
        if (result is None):
            log.debug('ASN    query    for    {0}'.format(self.dns_zone))
            data = self.dns_resolver.query(self.dns_zone, 'TXT')
            temp = str(data[0]).split('|')
        else:
            temp = result
        ret = {'asn_registry': temp[3].strip('    \n')}
        if (ret['asn_registry'] not in RIR_WHOIS.keys()):
            raise ASNRegistryError('ASN    registry    {0}    is    not    known.'.format(ret['asn_registry']))
        ret['asn'] = temp[0].strip('    "\n')
        ret['asn_cidr'] = temp[1].strip('    \n')
        ret['asn_country_code'] = temp[2].strip('    \n').upper()
        ret['asn_date'] = temp[4].strip('    "\n')
        return ret
    except ASNRegistryError:
        raise
    except (dns.resolver.NXDOMAIN, dns.resolver.NoNameservers, dns.resolver.NoAnswer, dns.exception.Timeout) as e:
        raise ASNLookupError('ASN    lookup    failed    (DNS    {0})    for    {1}.'.format(e.__class__.__name__, self.address_str))
    except:
        raise ASNLookupError('ASN    lookup    failed    for    {0}.'.format(self.address_str))
