'The function for retrieving ASN information for an IP address from
Arin via port 80 (HTTP). Currently limited to fetching asn_registry
through a Arin whois (REST) lookup. The other values are returned as
None to keep a consistent dict output. This should be used as a last
chance fallback call behind ASN DNS & ASN Whois lookups.
Args:
retry_count: The number of times to retry in case socket errors,
timeouts, connection resets, etc. are encountered.
result: Optional result object. This bypasses the ASN lookup.
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:
Dictionary: A dictionary containing the following keys:
asn (String) - None, can\'t retrieve with this method.
asn_date (String) - None, can\'t retrieve with this method.
asn_registry (String) - The assigned ASN registry.
asn_cidr (String) - None, can\'t retrieve with this method.
asn_country_code (String) - None, can\'t retrieve with this
method.
Raises:
ASNRegistryError: The ASN registry is not known.
ASNLookupError: The ASN lookup failed.'

def get_asn_http(self, retry_count=3, result=None, extra_org_map=None):

    org_map = ORG_MAP.copy()
    try:
        org_map.update(extra_org_map)
    except (TypeError, ValueError, IndexError, KeyError):
        pass
    try:
        if (result is None):
            log.debug('ASN    query    for    {0}'.format(self.address_str))
            response = self.get_http_json(url=str(ARIN).format(self.address_str), retry_count=retry_count, headers={'Accept': 'application/json'})
        else:
            response = result
        asn_data = {'asn_registry': None, 'asn': None, 'asn_cidr': None, 'asn_country_code': None, 'asn_date': None}
        try:
            net_list = response['nets']['net']
            if (not isinstance(net_list, list)):
                net_list = [net_list]
        except (KeyError, TypeError):
            log.debug('No    networks    found')
            net_list = []
        for n in net_list:
            try:
                asn_data['asn_registry'] = org_map[n['orgRef']['@handle'].upper()]
            except KeyError as e:
                log.debug('Could    not    parse    ASN    registry    via    HTTP:    {0}'.format(str(e)))
                raise ASNRegistryError('ASN    registry    lookup    failed.')
            break
        return asn_data
    except (socket.timeout, socket.error) as e:
        log.debug('ASN    query    socket    error:    {0}'.format(e))
        if (retry_count > 0):
            log.debug('ASN    query    retrying    (count:    {0})'.format(str(retry_count)))
            return self.get_asn_http(retry_count=(retry_count - 1))
        else:
            raise ASNLookupError('ASN    lookup    failed    for    {0}.'.format(self.address_str))
    except ASNRegistryError:
        raise
    except:
        raise ASNLookupError('ASN    lookup    failed    for    {0}.'.format(self.address_str))
