'The wrapper function for retrieving and parsing ASN information for an
IP address.
Args:
retry_count: The number of times to retry in case socket errors,
timeouts, connection resets, etc. are encountered.
asn_alts: Array of additional lookup types to attempt if the
ASN dns lookup fails. Allow permutations must be enabled.
Defaults to all [\'whois\', \'http\'].
extra_org_map: Dictionary mapping org handles to RIRs. This is for
limited cases where ARIN REST (ASN fallback HTTP lookup) does
not show an RIR as the org handle e.g., DNIC (which is now the
built in ORG_MAP) e.g., {\'DNIC\': \'arin\'}. Valid RIR values are
(note the case-sensitive - this is meant to match the REST
result): \'ARIN\', \'RIPE\', \'apnic\', \'lacnic\', \'afrinic\'
Returns:
Tuple:
:Dictionary: Result from get_asn_dns() or get_asn_whois().
:Dictionary: The response returned by get_asn_dns() or
get_asn_whois().
Raises:
ASNRegistryError: ASN registry does not match.
HTTPLookupError: The HTTP lookup failed.'

def lookup_asn(self, retry_count=3, asn_alts=None, extra_org_map=None):

    lookups = (asn_alts if (asn_alts is not None) else ['whois', 'http'])
    response = None
    try:
        self.dns_resolver.lifetime = (self.dns_resolver.timeout * ((retry_count and retry_count) or 1))
        asn_data = self.get_asn_dns()
    except (ASNLookupError, ASNRegistryError) as e:
        if (not self.allow_permutations):
            raise ASNRegistryError('ASN    registry    lookup    failed.    Permutations    not    allowed.')
        try:
            if ('whois' in lookups):
                log.debug('ASN    DNS    lookup    failed,    trying    ASN    WHOIS:    {0}'.format(e))
                asn_data = self.get_asn_whois(retry_count)
            else:
                raise ASNLookupError
        except (ASNLookupError, ASNRegistryError):
            if ('http' in lookups):
                log.debug('ASN    WHOIS    lookup    failed,    trying    ASN    via    HTTP')
                try:
                    asn_data = self.get_asn_http(retry_count=retry_count, extra_org_map=extra_org_map)
                except ASNRegistryError:
                    raise ASNRegistryError('ASN    registry    lookup    failed.')
                except ASNLookupError:
                    raise HTTPLookupError('ASN    HTTP    lookup    failed.')
            else:
                raise ASNRegistryError('ASN    registry    lookup    failed.')
    return (asn_data, response)
