Skip to content

Commit

Permalink
Merge pull request #242 from secynic/216/asn_origin_bug
Browse files Browse the repository at this point in the history
Fixed ASNOrigin lookups (#216)
  • Loading branch information
secynic committed Jul 31, 2019
2 parents 0816a27 + 566dc3e commit 8992461
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -13,6 +13,8 @@ Changelog
nir.NIRWhois._get_nets_krnic, nir.NIRWhois._get_contact (#230)
- Removed deprecated asn_alts parameter (#230)
- Removed deprecated allow_permutations parameter (#230)
- Fixed ASNOrigin lookups (#216)
- Fixed bug in ASNOrigin lookups when multiple asn_methods provided (#216)

1.1.0 (2019-02-01)
------------------
Expand Down
31 changes: 19 additions & 12 deletions ipwhois/asn.py
Expand Up @@ -61,21 +61,21 @@

ASN_ORIGIN_HTTP = {
'radb': {
'url': 'http://www.radb.net/query/',
'url': 'http://www.radb.net/query',
'form_data_asn_field': 'keywords',
'form_data': {
'advanced_query': '1',
'query': 'Query',
'-T option': 'inet-rtr',
# '-T option': 'inet-rtr',
'ip_option': '',
'-i': '1',
'-i option': 'origin'
},
'fields': {
'description': r'(descr):[^\S\n]+(?P<val>.+?)\<br\>',
'maintainer': r'(mnt-by):[^\S\n]+(?P<val>.+?)\<br\>',
'updated': r'(changed):[^\S\n]+(?P<val>.+?)\<br\>',
'source': r'(source):[^\S\n]+(?P<val>.+?)\<br\>',
'description': r'(descr):[^\S\n]+(?P<val>.+?)\n',
'maintainer': r'(mnt-by):[^\S\n]+(?P<val>.+?)\n',
'updated': r'(changed):[^\S\n]+(?P<val>.+?)\n',
'source': r'(source):[^\S\n]+(?P<val>.+?)\<',
}
},
}
Expand Down Expand Up @@ -796,6 +796,8 @@ def lookup(self, asn=None, inc_raw=False, retry_count=3, response=None,
asn=asn, retry_count=retry_count
)

break

except (WhoisLookupError, WhoisRateLimitError) as e:

log.debug('ASN origin WHOIS lookup failed: {0}'
Expand All @@ -809,17 +811,22 @@ def lookup(self, asn=None, inc_raw=False, retry_count=3, response=None,
log.debug('Response not given, perform ASN origin '
'HTTP lookup for: {0}'.format(asn))

tmp = ASN_ORIGIN_HTTP['radb']['form_data']
tmp[str(ASN_ORIGIN_HTTP['radb']['form_data_asn_field']
)] = asn
# tmp = ASN_ORIGIN_HTTP['radb']['form_data']
# tmp[str(
# ASN_ORIGIN_HTTP['radb']['form_data_asn_field']
# )] = asn
response = self._net.get_http_raw(
url=ASN_ORIGIN_HTTP['radb']['url'],
url=('{0}?advanced_query=1&keywords={1}&-T+option'
'=&ip_option=&-i=1&-i+option=origin'
).format(ASN_ORIGIN_HTTP['radb']['url'], asn),
retry_count=retry_count,
request_type='POST',
form_data=tmp
request_type='GET',
# form_data=tmp
)
is_http = True # pragma: no cover

break

except HTTPLookupError as e:

log.debug('ASN origin HTTP lookup failed: {0}'
Expand Down
3 changes: 2 additions & 1 deletion ipwhois/tests/online/test_asn.py
Expand Up @@ -96,4 +96,5 @@ def test_lookup(self):

net = Net(address='74.125.225.229')
asnorigin = ASNOrigin(net)
asnorigin.lookup(asn='15169', asn_methods=['whois', 'http'])
asnorigin.lookup(asn='15169', asn_methods=['whois'])
asnorigin.lookup(asn='15169', asn_methods=['http'])

0 comments on commit 8992461

Please sign in to comment.