From 566dc3e280a57ac6db1259dd027352223ca1b036 Mon Sep 17 00:00:00 2001 From: secynic Date: Wed, 31 Jul 2019 13:29:11 -0500 Subject: [PATCH] Fixed ASNOrigin lookups (#216) --- CHANGES.rst | 2 ++ ipwhois/asn.py | 31 +++++++++++++++++++------------ ipwhois/tests/online/test_asn.py | 3 ++- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 024080b..663cb00 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ------------------ diff --git a/ipwhois/asn.py b/ipwhois/asn.py index aaa4c33..60625e2 100644 --- a/ipwhois/asn.py +++ b/ipwhois/asn.py @@ -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.+?)\', - 'maintainer': r'(mnt-by):[^\S\n]+(?P.+?)\', - 'updated': r'(changed):[^\S\n]+(?P.+?)\', - 'source': r'(source):[^\S\n]+(?P.+?)\', + 'description': r'(descr):[^\S\n]+(?P.+?)\n', + 'maintainer': r'(mnt-by):[^\S\n]+(?P.+?)\n', + 'updated': r'(changed):[^\S\n]+(?P.+?)\n', + 'source': r'(source):[^\S\n]+(?P.+?)\<', } }, } @@ -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}' @@ -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}' diff --git a/ipwhois/tests/online/test_asn.py b/ipwhois/tests/online/test_asn.py index 62cd804..76bc8ce 100644 --- a/ipwhois/tests/online/test_asn.py +++ b/ipwhois/tests/online/test_asn.py @@ -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'])