From 8e1e6a8c1ecce726f1369dcd5cb9ffd3734b958c Mon Sep 17 00:00:00 2001 From: secynic Date: Thu, 3 Aug 2017 22:42:57 -0500 Subject: [PATCH 01/14] Fixed example output for lists (#196) --- ipwhois/scripts/docs/generate_examples.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ipwhois/scripts/docs/generate_examples.py b/ipwhois/scripts/docs/generate_examples.py index e34222d..d271912 100644 --- a/ipwhois/scripts/docs/generate_examples.py +++ b/ipwhois/scripts/docs/generate_examples.py @@ -310,8 +310,9 @@ tmp_query_results = {} for query_key, query in section_config['queries'].items(): + result = query() new_str = json.dumps( - query(), indent=4, sort_keys=True + result, indent=4, sort_keys=True ).replace(': null', ': None') new_str = re.sub( @@ -333,7 +334,9 @@ r'\\\\n', new_str, flags=re.DOTALL - )[:-1] + ' }' + )[:-1] + ' {0}'.format( + '}' if isinstance(result, dict) else ']' + ) output_str = section_config['content'].format( *tmp_query_results.values() From 01fb6210e59bc1f6f7b4cddabf60caa9cfc1dc3a Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 22 Sep 2017 17:47:58 +0200 Subject: [PATCH 02/14] Adds base exception --- ipwhois/exceptions.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/ipwhois/exceptions.py b/ipwhois/exceptions.py index 7e1c1f7..42749b7 100644 --- a/ipwhois/exceptions.py +++ b/ipwhois/exceptions.py @@ -23,83 +23,89 @@ # POSSIBILITY OF SUCH DAMAGE. -class NetError(Exception): +class BaseIpwhoisException(Exception): + """ + Base exception for all the ipwhois custom ones. + """ + + +class NetError(BaseIpwhoisException): """ An Exception for when a parameter provided is not an instance of ipwhois.net.Net. """ -class IPDefinedError(Exception): +class IPDefinedError(BaseIpwhoisException): """ An Exception for when the IP is defined (does not need to be resolved). """ -class ASNLookupError(Exception): +class ASNLookupError(BaseIpwhoisException): """ An Exception for when the ASN lookup failed. """ -class ASNRegistryError(Exception): +class ASNRegistryError(BaseIpwhoisException): """ An Exception for when the ASN registry does not match one of the five expected values (arin, ripencc, apnic, lacnic, afrinic). """ -class ASNParseError(Exception): +class ASNParseError(BaseIpwhoisException): """ An Exception for when the ASN parsing failed. """ -class ASNOriginLookupError(Exception): +class ASNOriginLookupError(BaseIpwhoisException): """ An Exception for when the ASN origin lookup failed. """ -class HostLookupError(Exception): +class HostLookupError(BaseIpwhoisException): """ An Exception for when the host lookup failed. """ -class BlacklistError(Exception): +class BlacklistError(BaseIpwhoisException): """ An Exception for when the server is in a blacklist. """ -class WhoisLookupError(Exception): +class WhoisLookupError(BaseIpwhoisException): """ An Exception for when the whois lookup failed. """ -class WhoisRateLimitError(Exception): +class WhoisRateLimitError(BaseIpwhoisException): """ An Exception for when Whois queries exceed the NIC's request limit and have exhausted all retries. """ -class HTTPLookupError(Exception): +class HTTPLookupError(BaseIpwhoisException): """ An Exception for when the RDAP lookup failed. """ -class HTTPRateLimitError(Exception): +class HTTPRateLimitError(BaseIpwhoisException): """ An Exception for when HTTP queries exceed the NIC's request limit and have exhausted all retries. """ -class InvalidEntityContactObject(Exception): +class InvalidEntityContactObject(BaseIpwhoisException): """ An Exception for when JSON output is not an RDAP entity contact information object: @@ -107,14 +113,14 @@ class InvalidEntityContactObject(Exception): """ -class InvalidNetworkObject(Exception): +class InvalidNetworkObject(BaseIpwhoisException): """ An Exception for when JSON output is not an RDAP network object: https://tools.ietf.org/html/rfc7483#section-5.4 """ -class InvalidEntityObject(Exception): +class InvalidEntityObject(BaseIpwhoisException): """ An Exception for when JSON output is not an RDAP entity object: https://tools.ietf.org/html/rfc7483#section-5.1 From 87642bdf0774a42c303d3cc803247568a4fa605b Mon Sep 17 00:00:00 2001 From: secynic Date: Mon, 28 Jan 2019 19:24:00 -0600 Subject: [PATCH 03/14] Fixed parsing bug in ASN HTTP lookup (#220) --- CHANGES.rst | 9 +++++++++ ipwhois/asn.py | 9 +++++++-- ipwhois/tests/test_asn.py | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3c41f8e..8817837 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,15 @@ Changelog ========= +1.1.0 (TBD) +----------- + +- Exceptions now inherit a new BaseIpwhoisException rather than Exception + (#205 - Darkheir) +- Fixed list output for generate_examples.py (#196) +- Fixed bug in ASN HTTP lookup where the ARIN results were reversed, and + parsing would fail on the first item (#220) + 1.0.0 (2017-07-30) ------------------ diff --git a/ipwhois/asn.py b/ipwhois/asn.py index 6f15fa1..6d39c73 100644 --- a/ipwhois/asn.py +++ b/ipwhois/asn.py @@ -371,7 +371,7 @@ def parse_fields_http(self, response, extra_org_map=None): log.debug('No networks found') net_list = [] - for n in net_list: + for n in reversed(net_list): try: @@ -383,10 +383,15 @@ def parse_fields_http(self, response, extra_org_map=None): log.debug('Could not parse ASN registry via HTTP: ' '{0}'.format(str(e))) - raise ASNRegistryError('ASN registry lookup failed.') + continue break + if not asn_data['asn_registry']: + + log.debug('Could not parse ASN registry via HTTP') + raise ASNRegistryError('ASN registry lookup failed.') + except ASNRegistryError: raise diff --git a/ipwhois/tests/test_asn.py b/ipwhois/tests/test_asn.py index 5bdb134..9e6db03 100644 --- a/ipwhois/tests/test_asn.py +++ b/ipwhois/tests/test_asn.py @@ -128,7 +128,8 @@ def test__parse_fields_http(self): data = '' try: - self.assertIsInstance(ipasn._parse_fields_http(response=data), dict) + self.assertRaises(ASNRegistryError, ipasn._parse_fields_http, + response=data) except AssertionError as e: raise e except Exception as e: From 881bd08af4a80bfcb864b463611b16cbfcdf39d9 Mon Sep 17 00:00:00 2001 From: secynic Date: Mon, 28 Jan 2019 20:26:00 -0600 Subject: [PATCH 04/14] Removed support for Python 2.6/3.3, added support for 3.7 (#221) --- .travis.yml | 8 ++----- CHANGES.rst | 1 + CONTRIBUTING.rst | 2 +- README.rst | 12 +++------- ipwhois/asn.py | 8 ++----- ipwhois/examples/elastic_search/README.rst | 9 +------ .../elastic_search/requirements26.txt | 4 ---- ipwhois/examples/redis_cache/README.rst | 8 +------ ipwhois/net.py | 18 -------------- ipwhois/scripts/ipwhois_cli.py | 6 ++--- ipwhois/tests/__init__.py | 24 ------------------- setup.py | 3 +-- 12 files changed, 14 insertions(+), 89 deletions(-) delete mode 100644 ipwhois/examples/elastic_search/requirements26.txt diff --git a/.travis.yml b/.travis.yml index 74836f2..eca6d79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,15 @@ language: python python: - - 2.6 - 2.7 - - 3.3 - 3.4 - 3.5 - 3.6 + - 3.7 install: - pip install --upgrade setuptools - pip install --upgrade pip - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then pip install -r requirements/python2.txt; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3.3* ]]; then pip install -r requirements/python3.txt; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3.4* ]]; then pip install -r requirements/python3.txt; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3.5* ]]; then pip install -r requirements/python3.txt; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then pip install -r requirements/python3.txt; fi + - if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then pip install -r requirements/python3.txt; fi - pip install coveralls - pip install codeclimate-test-reporter - pip install -e . diff --git a/CHANGES.rst b/CHANGES.rst index 8817837..94368ba 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,7 @@ Changelog - Fixed list output for generate_examples.py (#196) - Fixed bug in ASN HTTP lookup where the ARIN results were reversed, and parsing would fail on the first item (#220) +- Removed support for Python 2.6/3.3, added support for 3.7 (#221) 1.0.0 (2017-07-30) ------------------ diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index a4beceb..5808f7f 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -110,7 +110,7 @@ Guidelines - Follow the `Google docstring style guide `_ for comments -- Must be compatible with Python 2.6, 2.7, and 3.3+ +- Must be compatible with Python 2.7 and 3.4+ - Break out reusable code to functions - Make your code easy to read and comment where necessary - Reference the GitHub issue number in the description (e.g., Issue #01) diff --git a/README.rst b/README.rst index a11268e..879025c 100644 --- a/README.rst +++ b/README.rst @@ -11,7 +11,7 @@ ipwhois :target: https://codeclimate.com/github/secynic/ipwhois .. image:: https://img.shields.io/badge/license-BSD%202--Clause-blue.svg :target: https://github.com/secynic/ipwhois/tree/master/LICENSE.txt -.. image:: https://img.shields.io/badge/python-2.6%2C%202.7%2C%203.3+-blue.svg +.. image:: https://img.shields.io/badge/python-2.7%2C%203.4+-blue.svg :target: https://docs.python.org .. image:: https://img.shields.io/badge/docs-latest-green.svg?style=flat :target: https://ipwhois.readthedocs.io/en/latest @@ -45,7 +45,7 @@ Features * Recursive network parsing for IPs with parent/children networks listed * National Internet Registry support for JPNIC and KRNIC * Supports IP to ASN and ASN origin queries -* Python 2.6+ and 3.3+ supported +* Python 2.7 and 3.4+ supported * Useful set of utilities * Experimental bulk query support * BSD license @@ -97,18 +97,12 @@ https://ipwhois.readthedocs.io/en/latest/UPGRADING.html Dependencies ============ -Python 2.6:: - - dnspython - ipaddr - argparse (required only for CLI) - Python 2.7:: dnspython ipaddr -Python 3.3+:: +Python 3.4+:: dnspython diff --git a/ipwhois/asn.py b/ipwhois/asn.py index 6d39c73..68a6c40 100644 --- a/ipwhois/asn.py +++ b/ipwhois/asn.py @@ -480,9 +480,7 @@ def lookup(self, inc_raw=False, retry_count=3, asn_alts=None, else: - # Python 2.6 doesn't support set literal expressions, use explicit - # set() instead. - if set(['dns', 'whois', 'http']).isdisjoint(asn_methods): + if {'dns', 'whois', 'http'}.isdisjoint(asn_methods): raise ValueError('methods argument requires at least one of ' 'dns, whois, http.') @@ -844,9 +842,7 @@ def lookup(self, asn=None, inc_raw=False, retry_count=3, response=None, else: - # Python 2.6 doesn't support set literal expressions, use explicit - # set() instead. - if set(['whois', 'http']).isdisjoint(asn_methods): + if {'whois', 'http'}.isdisjoint(asn_methods): raise ValueError('methods argument requires at least one of ' 'whois, http.') diff --git a/ipwhois/examples/elastic_search/README.rst b/ipwhois/examples/elastic_search/README.rst index 3fc34d4..62de92a 100644 --- a/ipwhois/examples/elastic_search/README.rst +++ b/ipwhois/examples/elastic_search/README.rst @@ -22,14 +22,7 @@ Tested using:: ElasticSearch 5.5.1 Kibana 5.5.1 -Python 2.6 (requirements26.txt - geopy is not supported):: - - ipwhois - elasticsearch - geoip2 - argparse - -Python 2.7, 3.3+ (requirements.txt):: +Python 2.7, 3.4+ (requirements.txt):: ipwhois elasticsearch diff --git a/ipwhois/examples/elastic_search/requirements26.txt b/ipwhois/examples/elastic_search/requirements26.txt deleted file mode 100644 index 8c9f0ba..0000000 --- a/ipwhois/examples/elastic_search/requirements26.txt +++ /dev/null @@ -1,4 +0,0 @@ -ipwhois -elasticsearch -geoip2 -argparse diff --git a/ipwhois/examples/redis_cache/README.rst b/ipwhois/examples/redis_cache/README.rst index 1b1457e..4f81770 100644 --- a/ipwhois/examples/redis_cache/README.rst +++ b/ipwhois/examples/redis_cache/README.rst @@ -15,13 +15,7 @@ Tested using:: Redis 3.2.1 -Python 2.6 (requirements26.txt):: - - ipwhois - redis - argparse - -Python 2.7, 3.3+ (requirements.txt):: +Python 2.7, 3.4+ (requirements.txt):: ipwhois redis diff --git a/ipwhois/net.py b/ipwhois/net.py index 65b2881..a80ece0 100644 --- a/ipwhois/net.py +++ b/ipwhois/net.py @@ -768,15 +768,6 @@ def get_http_json(self, url=None, retry_count=3, rate_limit_timeout=120, except (URLError, socket.timeout, socket.error) as e: - # Check needed for Python 2.6, also why URLError is caught. - try: # pragma: no cover - if not isinstance(e.reason, (socket.timeout, socket.error)): - raise HTTPLookupError('HTTP lookup failed for {0}.' - ''.format(url)) - except AttributeError: # pragma: no cover - - pass - log.debug('HTTP query socket error: {0}'.format(e)) if retry_count > 0: @@ -920,15 +911,6 @@ def get_http_raw(self, url=None, retry_count=3, headers=None, except (URLError, socket.timeout, socket.error) as e: - # Check needed for Python 2.6, also why URLError is caught. - try: # pragma: no cover - if not isinstance(e.reason, (socket.timeout, socket.error)): - raise HTTPLookupError('HTTP lookup failed for {0}.' - ''.format(url)) - except AttributeError: # pragma: no cover - - pass - log.debug('HTTP query socket error: {0}'.format(e)) if retry_count > 0: diff --git a/ipwhois/scripts/ipwhois_cli.py b/ipwhois/scripts/ipwhois_cli.py index faf9a5b..56daa6a 100644 --- a/ipwhois/scripts/ipwhois_cli.py +++ b/ipwhois/scripts/ipwhois_cli.py @@ -482,10 +482,8 @@ def generate_output_asn(self, json_data=None, hr=True, show_name=False, if json_data is None: json_data = {} - # Python 2.6 doesn't support set literal expressions, use explicit - # set() instead. - keys = set(['asn', 'asn_cidr', 'asn_country_code', 'asn_date', - 'asn_registry', 'asn_description']).intersection(json_data) + keys = {'asn', 'asn_cidr', 'asn_country_code', 'asn_date', + 'asn_registry', 'asn_description'}.intersection(json_data) output = '' diff --git a/ipwhois/tests/__init__.py b/ipwhois/tests/__init__.py index 82e2ce6..fdfca02 100644 --- a/ipwhois/tests/__init__.py +++ b/ipwhois/tests/__init__.py @@ -4,30 +4,6 @@ class TestCommon(unittest.TestCase): longMessage = False - # Python 2.6 doesn't have unittest._formatMessage or - # unittest.util.safe_repr - # Borrowed and modified both functions from Python 2.7. - if not hasattr(unittest.TestCase, '_formatMessage'): - def safe_repr(self, obj, short=False): - try: - result = repr(obj) - except Exception: - result = object.__repr__(obj) - if not short or len(result) < 80: - return result - return result[:80] + ' [truncated]...' - - def _formatMessage(self, msg, standardMsg): - if not self.longMessage: - return msg or standardMsg - if msg is None: - return standardMsg - try: - return '{0} : {0}'.format(standardMsg, msg) - except UnicodeDecodeError: - return '{0} : {0}'.format(self.safe_repr(standardMsg), - self.safe_repr(msg)) - if not hasattr(unittest.TestCase, 'assertIsInstance'): def assertIsInstance(self, obj, cls, msg=None): if not isinstance(obj, cls): diff --git a/setup.py b/setup.py index 4e61331..090e821 100644 --- a/setup.py +++ b/setup.py @@ -52,13 +52,12 @@ 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Topic :: Internet', 'Topic :: Software Development', ] From 48058c604461fc01ca193a06330392562e080a51 Mon Sep 17 00:00:00 2001 From: secynic Date: Mon, 28 Jan 2019 20:41:04 -0600 Subject: [PATCH 05/14] Python 3.7 Travis workaround (#221) --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index eca6d79..a363b5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: python +sudo: required +dist: xenial python: - 2.7 - 3.4 From 8b69ef1cb7ebd83c4593ea6013bd1e1eadc28ddf Mon Sep 17 00:00:00 2001 From: secynic Date: Mon, 28 Jan 2019 22:21:14 -0600 Subject: [PATCH 06/14] Fixed deprecation warnings in core code (#203 - cstranex) --- CHANGES.rst | 1 + README.rst | 2 +- ipwhois/asn.py | 10 ++++---- ipwhois/ipwhois.py | 2 +- ipwhois/net.py | 2 +- ipwhois/nir.py | 10 ++++---- ipwhois/tests/online/test_asn.py | 13 ++++------ ipwhois/tests/online/test_net.py | 7 ++++-- ipwhois/tests/test_asn.py | 42 ++++++++++++++++---------------- ipwhois/tests/test_nir.py | 24 +++++++++--------- ipwhois/tests/test_whois.py | 18 +++++++------- ipwhois/whois.py | 10 ++++---- 12 files changed, 71 insertions(+), 70 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 94368ba..f872635 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,7 @@ Changelog - Fixed bug in ASN HTTP lookup where the ARIN results were reversed, and parsing would fail on the first item (#220) - Removed support for Python 2.6/3.3, added support for 3.7 (#221) +- Fixed deprecation warnings in core code (#203 - cstranex) 1.0.0 (2017-07-30) ------------------ diff --git a/README.rst b/README.rst index 879025c..3cd6f8e 100644 --- a/README.rst +++ b/README.rst @@ -174,7 +174,7 @@ Input | allow_permutations | bool | Allow net.Net() to use additional methods if | | | | DNS lookups to Cymru fail. *WARNING* | | | | deprecated in favor of new argument | -| | | asn_methods. Defaults to True. | +| | | asn_methods. Defaults to False. | +--------------------+--------+-----------------------------------------------+ RDAP (HTTP) diff --git a/ipwhois/asn.py b/ipwhois/asn.py index 68a6c40..2a7e563 100644 --- a/ipwhois/asn.py +++ b/ipwhois/asn.py @@ -511,7 +511,7 @@ def lookup(self, inc_raw=False, retry_count=3, asn_alts=None, asn_data_list = [] for asn_entry in response: - asn_data_list.append(self._parse_fields_dns( + asn_data_list.append(self.parse_fields_dns( str(asn_entry))) # Iterate through the parsed ASN results to find the @@ -544,7 +544,7 @@ def lookup(self, inc_raw=False, retry_count=3, asn_alts=None, try: response = self._net.get_asn_whois(retry_count) - asn_data = self._parse_fields_whois( + asn_data = self.parse_fields_whois( response) # pragma: no cover break @@ -560,7 +560,7 @@ def lookup(self, inc_raw=False, retry_count=3, asn_alts=None, response = self._net.get_asn_http( retry_count=retry_count ) - asn_data = self._parse_fields_http(response, + asn_data = self.parse_fields_http(response, extra_org_map) break @@ -916,7 +916,7 @@ def lookup(self, asn=None, inc_raw=False, retry_count=3, response=None, results['raw'] = response nets = [] - nets_response = self._get_nets_radb(response, is_http) + nets_response = self.get_nets_radb(response, is_http) nets.extend(nets_response) @@ -936,7 +936,7 @@ def lookup(self, asn=None, inc_raw=False, retry_count=3, response=None, section_end = nets[index + 1]['start'] - temp_net = self._parse_fields( + temp_net = self.parse_fields( response, fields['radb']['fields'], section_end, diff --git a/ipwhois/ipwhois.py b/ipwhois/ipwhois.py index d481dca..26b8acb 100644 --- a/ipwhois/ipwhois.py +++ b/ipwhois/ipwhois.py @@ -48,7 +48,7 @@ class IPWhois: """ def __init__(self, address, timeout=5, proxy_opener=None, - allow_permutations=True): + allow_permutations=False): self.net = Net( address=address, timeout=timeout, proxy_opener=proxy_opener, diff --git a/ipwhois/net.py b/ipwhois/net.py index a80ece0..1e5b9d7 100644 --- a/ipwhois/net.py +++ b/ipwhois/net.py @@ -113,7 +113,7 @@ class Net: """ def __init__(self, address, timeout=5, proxy_opener=None, - allow_permutations=True): + allow_permutations=False): # IPv4Address or IPv6Address if isinstance(address, IPv4Address) or isinstance( diff --git a/ipwhois/nir.py b/ipwhois/nir.py index 741b4e9..bb4f0c9 100644 --- a/ipwhois/nir.py +++ b/ipwhois/nir.py @@ -483,7 +483,7 @@ def get_contact(self, response=None, nir=None, handle=None, request_type=NIR_WHOIS[nir]['request_type'] ) - return self._parse_fields( + return self.parse_fields( response=contact_response, fields_dict=NIR_WHOIS[nir]['contact_fields'], dt_format=dt_format, @@ -582,11 +582,11 @@ def lookup(self, nir=None, inc_raw=False, retry_count=3, response=None, nets_response = None if nir == 'jpnic': - nets_response = self._get_nets_jpnic(response) + nets_response = self.get_nets_jpnic(response) elif nir == 'krnic': - nets_response = self._get_nets_krnic(response) + nets_response = self.get_nets_krnic(response) nets.extend(nets_response) @@ -609,7 +609,7 @@ def lookup(self, nir=None, inc_raw=False, retry_count=3, response=None, dt_format = None - temp_net = self._parse_fields( + temp_net = self.parse_fields( response=response, fields_dict=NIR_WHOIS[nir]['fields'], net_start=section_end, @@ -659,7 +659,7 @@ def lookup(self, nir=None, inc_raw=False, retry_count=3, response=None, tmp_response = None tmp_handle = contact - temp_net['contacts'][key] = self._get_contact( + temp_net['contacts'][key] = self.get_contact( response=tmp_response, handle=tmp_handle, nir=nir, diff --git a/ipwhois/tests/online/test_asn.py b/ipwhois/tests/online/test_asn.py index fa2e3b2..62cd804 100644 --- a/ipwhois/tests/online/test_asn.py +++ b/ipwhois/tests/online/test_asn.py @@ -35,16 +35,14 @@ def test_lookup(self): ipasn.lookup(asn_methods=['dns', 'whois', 'http']) ipasn.lookup(asn_methods=['http']) - net = Net(address='74.125.225.229', timeout=0, - allow_permutations=False) + net = Net(address='74.125.225.229', timeout=0) ipasn = IPASN(net) self.assertRaises(ASNRegistryError, ipasn.lookup) - net = Net(address='74.125.225.229', timeout=0, - allow_permutations=True) + net = Net(address='74.125.225.229', timeout=0) ipasn = IPASN(net) self.assertRaises(ASNRegistryError, ipasn.lookup, **dict( - asn_alts=['http'])) + asn_methods=['http'])) class TestASNOrigin(TestCommon): @@ -86,12 +84,11 @@ def test_lookup(self): self.fail('Unexpected exception raised: {0}'.format(e)) - net = Net(address='74.125.225.229', timeout=0, - allow_permutations=True) + net = Net(address='74.125.225.229', timeout=0) asnorigin = ASNOrigin(net) self.assertRaises(ASNOriginLookupError, asnorigin.lookup, **dict( asn='15169', - asn_alts=['http'])) + asn_methods=['http'])) self.assertRaises(ValueError, asnorigin.lookup, **dict( asn='15169', diff --git a/ipwhois/tests/online/test_net.py b/ipwhois/tests/online/test_net.py index 7e86dc2..af9d518 100644 --- a/ipwhois/tests/online/test_net.py +++ b/ipwhois/tests/online/test_net.py @@ -3,6 +3,7 @@ from ipwhois.exceptions import (ASNLookupError, ASNRegistryError, BlacklistError, WhoisLookupError, HTTPLookupError, HostLookupError) +from ipwhois.asn import IPASN from ipwhois.net import Net LOG_FORMAT = ('[%(asctime)s] [%(levelname)s] [%(filename)s:%(lineno)s] ' @@ -14,10 +15,12 @@ class TestNet(TestCommon): def test_lookup_asn(self): - # TODO: keep until deprecated lookup is removed, for coverage + net = Net('74.125.225.229') + ipasn = IPASN(net) + try: - self.assertIsInstance(net.lookup_asn(), tuple) + self.assertIsInstance(ipasn.lookup(), dict) except HTTPLookupError: pass except AssertionError as e: diff --git a/ipwhois/tests/test_asn.py b/ipwhois/tests/test_asn.py index 9e6db03..e27a1b1 100644 --- a/ipwhois/tests/test_asn.py +++ b/ipwhois/tests/test_asn.py @@ -21,23 +21,23 @@ def test_IPASN(self): self.assertRaises(NetError, IPASN, 'a') - def test__parse_fields_dns(self): + def test_parse_fields_dns(self): data = '"15169 | 74.125.225.0/24 | US | arin | 2007-03-13"' net = Net('74.125.225.229') ipasn = IPASN(net) try: - self.assertIsInstance(ipasn._parse_fields_dns(data), dict) + self.assertIsInstance(ipasn.parse_fields_dns(data), dict) except AssertionError as e: raise e except Exception as e: self.fail('Unexpected exception raised: {0}'.format(e)) data = '"15169 | 74.125.225.0/24 | US | random | 2007-03-13"' - self.assertRaises(ASNRegistryError, ipasn._parse_fields_dns, data) + self.assertRaises(ASNRegistryError, ipasn.parse_fields_dns, data) data = '' - self.assertRaises(ASNParseError, ipasn._parse_fields_dns, data) + self.assertRaises(ASNParseError, ipasn.parse_fields_dns, data) def test_parse_fields_verbose_dns(self): @@ -58,14 +58,14 @@ def test_parse_fields_verbose_dns(self): data = '' self.assertRaises(ASNParseError, ipasn.parse_fields_verbose_dns, data) - def test__parse_fields_whois(self): + def test_parse_fields_whois(self): data = ('15169 | 74.125.225.229 | 74.125.225.0/24 | US | arin' ' | 2007-03-13 | GOOGLE - Google Inc., US') net = Net('74.125.225.229') ipasn = IPASN(net) try: - self.assertIsInstance(ipasn._parse_fields_whois(data), dict) + self.assertIsInstance(ipasn.parse_fields_whois(data), dict) except AssertionError as e: raise e except Exception as e: @@ -73,12 +73,12 @@ def test__parse_fields_whois(self): data = ('15169 | 74.125.225.229 | 74.125.225.0/24 | US | rdm' ' | 2007-03-13 | GOOGLE - Google Inc., US') - self.assertRaises(ASNRegistryError, ipasn._parse_fields_whois, data) + self.assertRaises(ASNRegistryError, ipasn.parse_fields_whois, data) data = '15169 | 74.125.225.229 | 74.125.225.0/24 | US' - self.assertRaises(ASNParseError, ipasn._parse_fields_whois, data) + self.assertRaises(ASNParseError, ipasn.parse_fields_whois, data) - def test__parse_fields_http(self): + def test_parse_fields_http(self): data = { 'nets': { @@ -92,7 +92,7 @@ def test__parse_fields_http(self): net = Net('1.2.3.4') ipasn = IPASN(net) try: - self.assertIsInstance(ipasn._parse_fields_http(response=data), + self.assertIsInstance(ipasn.parse_fields_http(response=data), dict) except AssertionError as e: raise e @@ -101,7 +101,7 @@ def test__parse_fields_http(self): data['nets']['net']['orgRef']['@handle'] = 'RIPE' try: - self.assertIsInstance(ipasn._parse_fields_http(response=data), + self.assertIsInstance(ipasn.parse_fields_http(response=data), dict) except AssertionError as e: raise e @@ -110,7 +110,7 @@ def test__parse_fields_http(self): data['nets']['net']['orgRef']['@handle'] = 'DNIC' try: - self.assertIsInstance(ipasn._parse_fields_http(response=data), + self.assertIsInstance(ipasn.parse_fields_http(response=data), dict) except AssertionError as e: raise e @@ -119,7 +119,7 @@ def test__parse_fields_http(self): data['nets']['net']['orgRef']['@handle'] = 'INVALID' try: - self.assertRaises(ASNRegistryError, ipasn._parse_fields_http, + self.assertRaises(ASNRegistryError, ipasn.parse_fields_http, response=data) except AssertionError as e: raise e @@ -128,7 +128,7 @@ def test__parse_fields_http(self): data = '' try: - self.assertRaises(ASNRegistryError, ipasn._parse_fields_http, + self.assertRaises(ASNRegistryError, ipasn.parse_fields_http, response=data) except AssertionError as e: raise e @@ -175,7 +175,7 @@ def test__ASNOriginLookup(self): self.fail('Unexpected exception raised: {0}'.format(e)) - def test__parse_fields(self): + def test_parse_fields(self): net = Net('74.125.225.229') obj = ASNOrigin(net) @@ -184,12 +184,12 @@ def test__parse_fields(self): # groups are messed up. tmp_dict = ASN_ORIGIN_WHOIS['radb']['fields'] tmp_dict['route'] = r'(route):[^\S\n]+(?P.+?)\n' - obj._parse_fields( + obj.parse_fields( response="\nroute: 66.249.64.0/20\n", fields_dict=tmp_dict ) - obj._parse_fields( + obj.parse_fields( response="\nchanged: noc@google.com 20110301\n", fields_dict=ASN_ORIGIN_WHOIS['radb']['fields'] ) @@ -211,7 +211,7 @@ def test__parse_fields(self): '\nsource: RADB' '\n\n' ) - obj._parse_fields( + obj.parse_fields( response=multi_net_response, fields_dict=ASN_ORIGIN_WHOIS['radb']['fields'] ) @@ -240,9 +240,9 @@ def test__get_nets_radb(self): '\nsource: RADB' '\n\n' ) - obj._get_nets_radb(multi_net_response) + obj.get_nets_radb(multi_net_response) - self.assertEqual(obj._get_nets_radb(multi_net_response, is_http=True), + self.assertEqual(obj.get_nets_radb(multi_net_response, is_http=True), []) net = Net('2001:43f8:7b0::') @@ -259,7 +259,7 @@ def test__get_nets_radb(self): '\n\n' ) self.assertEquals( - obj._get_nets_radb(multi_net_response), + obj.get_nets_radb(multi_net_response), [{ 'updated': None, 'maintainer': None, diff --git a/ipwhois/tests/test_nir.py b/ipwhois/tests/test_nir.py index a855e82..6cecce2 100644 --- a/ipwhois/tests/test_nir.py +++ b/ipwhois/tests/test_nir.py @@ -57,7 +57,7 @@ def test_lookup(self): self.assertRaises(KeyError, obj.lookup) self.assertRaises(KeyError, obj.lookup, **dict(nir='a')) - def test__parse_fields(self): + def test_parse_fields(self): net = Net('133.1.2.5') obj = NIRWhois(net) @@ -66,13 +66,13 @@ def test__parse_fields(self): # groups are messed up. tmp_dict = NIR_WHOIS['jpnic']['fields'] tmp_dict['name'] = r'(NetName):[^\S\n]+(?P.+?)\n' - obj._parse_fields( + obj.parse_fields( response='\nNetName: TEST\n', fields_dict=tmp_dict, dt_format=NIR_WHOIS['jpnic']['dt_format'] ) - obj._parse_fields( + obj.parse_fields( response='\nUpdated: 2012-02-24\n', fields_dict=NIR_WHOIS['jpnic']['fields'], dt_format=NIR_WHOIS['jpnic']['dt_format'] @@ -81,13 +81,13 @@ def test__parse_fields(self): log.debug( 'Testing field parse error. This should be followed by a ' 'debug log.') - obj._parse_fields( + obj.parse_fields( response='\nUpdated: 2012-02-244\n', fields_dict=NIR_WHOIS['jpnic']['fields'], dt_format=NIR_WHOIS['jpnic']['dt_format'] ) - def test__get_nets_jpnic(self): + def test_get_nets_jpnic(self): net = Net('133.1.2.5') obj = NIRWhois(net) @@ -98,9 +98,9 @@ def test__get_nets_jpnic(self): 'a. [Network Number] asd>133.1.0.0/16' 'a. [Network Number] asd>133.1.0.0/24' ) - obj._get_nets_jpnic(multi_net_response) + obj.get_nets_jpnic(multi_net_response) - self.assertFalse(obj._get_nets_jpnic( + self.assertFalse(obj.get_nets_jpnic( 'a. [Network Number] asd>asd/16' )) @@ -115,19 +115,19 @@ def test__get_nets_krnic(self): 'IPv4 Address : 115.0.0.0 - 115.23.255.255 (/12+/13)' 'IPv4 Address : 115.1.2.0 - 115.1.2.63 (/26)' ) - obj._get_nets_krnic(multi_net_response) + obj.get_nets_krnic(multi_net_response) # ip_network ValueError - self.assertFalse(obj._get_nets_krnic( + self.assertFalse(obj.get_nets_krnic( 'IPv4 Address : asd - asd (/12+/13)' )) # Expected IP range regex not found, but some value found - self.assertFalse(obj._get_nets_krnic( + self.assertFalse(obj.get_nets_krnic( 'IPv4 Address : asd' )) - def test__get_contact(self): + def test_get_contact(self): net = Net('115.1.2.3') obj = NIRWhois(net) @@ -139,7 +139,7 @@ def test__get_contact(self): ) # No exception raised. - obj._get_contact( + obj.get_contact( response=contact_response, handle=None, nir='krnic', diff --git a/ipwhois/tests/test_whois.py b/ipwhois/tests/test_whois.py index c4d268d..36d507e 100644 --- a/ipwhois/tests/test_whois.py +++ b/ipwhois/tests/test_whois.py @@ -56,13 +56,13 @@ def test__parse_fields(self): # groups are messed up. tmp_dict = RIR_WHOIS['arin']['fields'] tmp_dict['name'] = r'(NetName):[^\S\n]+(?P.+?)\n' - obj._parse_fields( + obj.parse_fields( response="\nNetName: TEST\n", fields_dict=tmp_dict, dt_format=RIR_WHOIS['arin']['dt_format'] ) - obj._parse_fields( + obj.parse_fields( response="\nUpdated: 2012-02-24\n", fields_dict=RIR_WHOIS['arin']['fields'], dt_format=RIR_WHOIS['arin']['dt_format'] @@ -70,13 +70,13 @@ def test__parse_fields(self): log.debug('Testing field parse error. This should be followed by a ' 'debug log.') - obj._parse_fields( + obj.parse_fields( response='\nUpdated: 2012-02-244\n', fields_dict=RIR_WHOIS['arin']['fields'], dt_format=RIR_WHOIS['arin']['dt_format'] ) - def test__get_nets_arin(self): + def test_get_nets_arin(self): net = Net('74.125.225.229') obj = Whois(net) @@ -90,9 +90,9 @@ def test__get_nets_arin(self): '\nNetRange: 74.125.1.0 - 74.125.1.0' '\n' ) - obj._get_nets_arin(multi_net_response) + obj.get_nets_arin(multi_net_response) - def test__get_nets_lacnic(self): + def test_get_nets_lacnic(self): net = Net('200.57.141.161') obj = Whois(net) @@ -103,9 +103,9 @@ def test__get_nets_lacnic(self): '\ninetnum: 200.57.256/19\r\n' '\n' ) - obj._get_nets_lacnic(multi_net_response) + obj.get_nets_lacnic(multi_net_response) - def test__get_nets_other(self): + def test_get_nets_other(self): net = Net('210.107.73.73') obj = Whois(net) @@ -116,4 +116,4 @@ def test__get_nets_other(self): '\ninetnum: 210.107.0.0 - 210.107.127.256\n' '\n' ) - obj._get_nets_other(multi_net_response) + obj.get_nets_other(multi_net_response) diff --git a/ipwhois/whois.py b/ipwhois/whois.py index 87b43fa..fb2bfe2 100644 --- a/ipwhois/whois.py +++ b/ipwhois/whois.py @@ -740,7 +740,7 @@ def lookup(self, inc_raw=False, retry_count=3, response=None, results['raw_referral'] = response_ref - temp_rnet = self._parse_fields( + temp_rnet = self.parse_fields( response_ref, RWHOIS['fields'], field_list=field_list @@ -758,15 +758,15 @@ def lookup(self, inc_raw=False, retry_count=3, response=None, if asn_data['asn_registry'] == 'arin': - nets_response = self._get_nets_arin(response) + nets_response = self.get_nets_arin(response) elif asn_data['asn_registry'] == 'lacnic': - nets_response = self._get_nets_lacnic(response) + nets_response = self.get_nets_lacnic(response) else: - nets_response = self._get_nets_other(response) + nets_response = self.get_nets_other(response) nets.extend(nets_response) @@ -788,7 +788,7 @@ def lookup(self, inc_raw=False, retry_count=3, response=None, dt_format = None - temp_net = self._parse_fields( + temp_net = self.parse_fields( response, RIR_WHOIS[asn_data['asn_registry']]['fields'], section_end, From 7bf33a56d86cd7d3dc9ca423b66cbbeb3d28e3bf Mon Sep 17 00:00:00 2001 From: secynic Date: Wed, 30 Jan 2019 20:03:30 -0600 Subject: [PATCH 07/14] Fixed bug in host argument, ES 6.6.0, set user agent (#202) --- CHANGES.rst | 3 + ipwhois/examples/elastic_search/README.rst | 9 +- .../examples/elastic_search/elastic_search.py | 86 ++++++++++++------- 3 files changed, 66 insertions(+), 32 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index f872635..62eab6e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,6 +11,9 @@ Changelog parsing would fail on the first item (#220) - Removed support for Python 2.6/3.3, added support for 3.7 (#221) - Fixed deprecation warnings in core code (#203 - cstranex) +- Fixed bug in host argument for elastic_search.py example (#202) +- Set user agent in elastic_search.py example to avoid default user agent +- Updated elastic_search.py example for ES 6.6.0 1.0.0 (2017-07-30) ------------------ diff --git a/ipwhois/examples/elastic_search/README.rst b/ipwhois/examples/elastic_search/README.rst index 62de92a..4691c34 100644 --- a/ipwhois/examples/elastic_search/README.rst +++ b/ipwhois/examples/elastic_search/README.rst @@ -14,13 +14,18 @@ I do not re-distribute the GeoLite2 database. For geolite2 data, download the GeoLite2 database GeoLite2-City.mmdb and place in the data directory: https://dev.maxmind.com/geoip/geoip2/geolite2/ +.. note:: + + I have not updated the kibana.json since the ES 5.5.1 example. --kimport + and --kexport will not work with it for ES 6.x. + Dependencies ============ Tested using:: - ElasticSearch 5.5.1 - Kibana 5.5.1 + ElasticSearch 6.6.0 + Kibana 6.6.0 Python 2.7, 3.4+ (requirements.txt):: diff --git a/ipwhois/examples/elastic_search/elastic_search.py b/ipwhois/examples/elastic_search/elastic_search.py index fa21ab8..5a15f6a 100644 --- a/ipwhois/examples/elastic_search/elastic_search.py +++ b/ipwhois/examples/elastic_search/elastic_search.py @@ -9,6 +9,7 @@ from elasticsearch.helpers import scan from ipwhois import IPWhois from ipwhois.utils import get_countries +from ipwhois import __version__ from datetime import datetime import geoip2.database import json @@ -16,14 +17,11 @@ import sys from os import path -# geopy does not support lower than Python 2.7 -if sys.version_info >= (2, 7): +from geopy.geocoders import Nominatim +from geopy.exc import (GeocoderQueryError, GeocoderTimedOut) - from geopy.geocoders import Nominatim - from geopy.exc import (GeocoderQueryError, GeocoderTimedOut) - - # Used to convert addresses to geo locations. - GEOLOCATOR = Nominatim() +# Used to convert addresses to geo locations. +GEOLOCATOR = Nominatim(user_agent='ipwhois/{0}'.format(__version__)) # Setup the arg parser. parser = argparse.ArgumentParser( @@ -89,7 +87,7 @@ type=str, nargs=1, metavar='"HOST"', - default='localhost', + default=['localhost'], help='The ElasticSearch host to connect to. Default: "localhost".' ) parser.add_argument( @@ -108,8 +106,8 @@ 'date_detection': 'true', 'properties': { '@version': { - 'type': 'string', - 'index': 'not_analyzed' + 'type': 'text', + 'index': False }, 'updated': { 'type': 'date', @@ -117,7 +115,6 @@ 'ignore_malformed': 'false' } }, - '_all': {'enabled': 'true'}, 'dynamic_templates': [ { 'string_fields': { @@ -142,7 +139,7 @@ COUNTRIES = get_countries() # Default: localhost:9200 -es = elasticsearch.Elasticsearch(host=args.host, port=args.port) +es = elasticsearch.Elasticsearch(host=args.host[0], port=args.port) def delete_index(): @@ -150,7 +147,16 @@ def delete_index(): try: # Delete existing entries - es.indices.delete(index='ipwhois') + es.indices.delete(index='ipwhois_base') + + except elasticsearch.exceptions.NotFoundError: + + pass + + try: + + # Delete existing entries + es.indices.delete(index='ipwhois_entity') except elasticsearch.exceptions.NotFoundError: @@ -159,8 +165,27 @@ def delete_index(): def create_index(): - # Create the ipwhois index - es.indices.create(index='ipwhois', ignore=400, body={ + # Create the ipwhois_base index + es.indices.create(index='ipwhois_base', ignore=400, body={ + 'settings': { + 'index.refresh_interval': '5s', + 'analysis': { + 'analyzer': { + 'base': { + 'type': 'standard', + 'stopwords': '_none_' + }, + 'entity': { + 'type': 'standard', + 'stopwords': '_none_' + } + } + } + } + }) + + # Create the ipwhois_entity index + es.indices.create(index='ipwhois_entity', ignore=400, body={ 'settings': { 'index.refresh_interval': '5s', 'analysis': { @@ -219,7 +244,7 @@ def create_index(): }) es.indices.put_mapping( - index='ipwhois', + index='ipwhois_base', doc_type='base', body=mapping, allow_no_indices=True @@ -236,7 +261,7 @@ def create_index(): 'type': 'geo_point' }, 'value': { - 'type': 'string', + 'type': 'text', } } } @@ -244,7 +269,7 @@ def create_index(): } }) es.indices.put_mapping( - index='ipwhois', + index='ipwhois_entity', doc_type='entity', body=mapping, allow_no_indices=True @@ -258,7 +283,7 @@ def insert(input_ip='', update=True, expires=7, depth=1): try: # Only update if older than x days. tmp = es.search( - index='ipwhois', + index='ipwhois_base', doc_type='base', body={ 'query': { @@ -303,7 +328,7 @@ def insert(input_ip='', update=True, expires=7, depth=1): # Only update if older than 7 days. es_tmp = es.search( - index='ipwhois', + index='ipwhois_entity', doc_type='entity', body={ 'query': { @@ -369,7 +394,7 @@ def insert(input_ip='', update=True, expires=7, depth=1): try: ent_search = es.search( - index='ipwhois', + index='ipwhois_entity', doc_type='entity', body={ 'query': { @@ -382,7 +407,7 @@ def insert(input_ip='', update=True, expires=7, depth=1): for hit in ent_search['hits']['hits']: - es.delete(index='ipwhois', doc_type='entity', + es.delete(index='ipwhois_entity', doc_type='entity', id=hit['_id']) except KeyError: @@ -390,10 +415,10 @@ def insert(input_ip='', update=True, expires=7, depth=1): pass # Index the entity in elasticsearch. - es.index(index='ipwhois', doc_type='entity', body=ent) + es.index(index='ipwhois_entity', doc_type='entity', body=ent) # Refresh the index for searching duplicates. - es.indices.refresh(index='ipwhois') + es.indices.refresh(index='ipwhois_entity') # Don't need the objects key since that data has been entered as the # entities doc_type. @@ -451,7 +476,7 @@ def insert(input_ip='', update=True, expires=7, depth=1): try: ip_search = es.search( - index='ipwhois', + index='ipwhois_base', doc_type='base', body={ 'query': { @@ -464,17 +489,18 @@ def insert(input_ip='', update=True, expires=7, depth=1): for hit in ip_search['hits']['hits']: - es.delete(index='ipwhois', doc_type='base', id=hit['_id']) + es.delete(index='ipwhois_base', doc_type='base', id=hit['_id']) except KeyError: pass # Index the base in elasticsearch. - es.index(index='ipwhois', doc_type='base', body=ret) + es.index(index='ipwhois_base', doc_type='base', body=ret) - # Refresh the index for searching duplicates. - es.indices.refresh(index='ipwhois') + # Refresh the indices for searching duplicates. + es.indices.refresh(index='ipwhois_base') + es.indices.refresh(index='ipwhois_entity') if args.delete: @@ -501,7 +527,7 @@ def insert(input_ip='', update=True, expires=7, depth=1): client=es, index='.kibana', doc_type='index-pattern', - query={'query': {'match': {'_id': 'ipwhois'}}} + query={'query': {'match': {'_id': 'ipwhois*'}}} )) # Dump exports to json file. From afafb3c9a0d54be0d449d1dea7a2790f080e0207 Mon Sep 17 00:00:00 2001 From: secynic Date: Wed, 30 Jan 2019 22:16:01 -0600 Subject: [PATCH 08/14] Readme update for RDAP vs Legacy Whois output (#204) --- CHANGES.rst | 1 + README.rst | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 62eab6e..9114224 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,7 @@ Changelog - Fixed bug in host argument for elastic_search.py example (#202) - Set user agent in elastic_search.py example to avoid default user agent - Updated elastic_search.py example for ES 6.6.0 +- Readme update for RDAP vs Legacy Whois output (#204) 1.0.0 (2017-07-30) ------------------ diff --git a/README.rst b/README.rst index 3cd6f8e..2442df5 100644 --- a/README.rst +++ b/README.rst @@ -193,6 +193,17 @@ https://ipwhois.readthedocs.io/en/latest/RDAP.html Legacy Whois ------------ +.. note:: + + Legacy Whois output is different from RDAP. See the below JSON outputs for + a comparison: + + Legacy Whois: + https://ipwhois.readthedocs.io/en/latest/WHOIS.html#basic-usage + + RDAP: + https://ipwhois.readthedocs.io/en/latest/RDAP.html#basic-usage + Legacy Whois documentation: https://ipwhois.readthedocs.io/en/latest/WHOIS.html From 0231bf52a078b10a25dac4b6516c507851339e58 Mon Sep 17 00:00:00 2001 From: secynic Date: Wed, 30 Jan 2019 23:05:14 -0600 Subject: [PATCH 09/14] Removed the disallow_permutations argument from ipwhois_cli.py (#226) --- CHANGES.rst | 1 + CLI.rst | 8 +------- UPGRADING.rst | 9 +++++++++ ipwhois/scripts/ipwhois_cli.py | 24 ++++-------------------- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9114224..77586a8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,6 +15,7 @@ Changelog - Set user agent in elastic_search.py example to avoid default user agent - Updated elastic_search.py example for ES 6.6.0 - Readme update for RDAP vs Legacy Whois output (#204) +- Removed the disallow_permutations argument from ipwhois_cli.py (#226) 1.0.0 (2017-07-30) ------------------ diff --git a/CLI.rst b/CLI.rst index 5c8b360..cf4a986 100644 --- a/CLI.rst +++ b/CLI.rst @@ -20,7 +20,7 @@ Usage ipwhois_cli.py [-h] [--whois] [--exclude_nir] [--json] [--hr] [--show_name] [--colorize] [--timeout TIMEOUT] [--proxy_http "PROXY_HTTP"] - [--proxy_https "PROXY_HTTPS"] [--disallow_permutations] + [--proxy_https "PROXY_HTTPS"] [--inc_raw] [--retry_count RETRY_COUNT] [--asn_alts "ASN_ALTS"] [--asn_methods "ASN_METHODS"] [--extra_org_map "EXTRA_ORG_MAP"] @@ -60,12 +60,6 @@ IPWhois settings: The proxy HTTPS address passed to request.ProxyHandler. User auth can be passed like "https://user:pass@192.168.0.1:443" - --disallow_permutations - Disable additional methods if DNS lookups to Cymru - fail. This is the opposite of the ipwhois - allow_permutations, in order to enable - allow_permutations by default in the CLI. *WARNING* - deprecated in favor of new argument asn_methods. Common settings (RDAP & Legacy Whois): --inc_raw Include the raw whois results in the output. diff --git a/UPGRADING.rst b/UPGRADING.rst index 004aec2..3fdca30 100644 --- a/UPGRADING.rst +++ b/UPGRADING.rst @@ -9,6 +9,15 @@ any changes that may affect user experience when upgrading to a new release. This page is new as of version 1.0.0. Any information on older versions is likely missing or incomplete. +****** +v1.1.0 +****** + +- Exceptions now inherit a new BaseIpwhoisException rather than Exception +- Removed support for Python 2.6/3.3, added support for 3.7 +- Removed the disallow_permutations argument from ipwhois_cli.py. Use + ans_methods instead. + ****** v1.0.0 ****** diff --git a/ipwhois/scripts/ipwhois_cli.py b/ipwhois/scripts/ipwhois_cli.py index 56daa6a..ef957e3 100644 --- a/ipwhois/scripts/ipwhois_cli.py +++ b/ipwhois/scripts/ipwhois_cli.py @@ -150,15 +150,6 @@ 'can be passed like "https://user:pass@192.168.0.1:443"', required=False ) -group.add_argument( - '--disallow_permutations', - action='store_true', - help='Disable additional methods if DNS lookups to Cymru fail. This is the' - ' opposite of the ipwhois allow_permutations, in order to enable ' - 'allow_permutations by default in the CLI. *WARNING* deprecated in ' - 'favor of new argument asn_methods.', - default=False -) # Common (RDAP & Legacy Whois) group = parser.add_argument_group('Common settings (RDAP & Legacy Whois)') @@ -372,9 +363,6 @@ class IPWhoisCLI: proxy HTTP support or None. proxy_https (:obj:`urllib.request.OpenerDirector`): The request for proxy HTTPS support or None. - allow_permutations (:obj:`bool`): Allow net.Net() to use additional - methods if DNS lookups to Cymru fail. *WARNING* deprecated in - favor of new argument asn_methods. Defaults to True. """ def __init__( @@ -382,8 +370,7 @@ def __init__( addr, timeout, proxy_http, - proxy_https, - allow_permutations + proxy_https ): self.addr = addr @@ -412,12 +399,9 @@ def __init__( handler = ProxyHandler(handler_dict) self.opener = build_opener(handler) - self.allow_permutations = allow_permutations - self.obj = IPWhois(address=self.addr, timeout=self.timeout, - proxy_opener=self.opener, - allow_permutations=self.allow_permutations) + proxy_opener=self.opener) def generate_output_header(self, query_type='RDAP'): """ @@ -1442,6 +1426,7 @@ def lookup_whois(self, hr=True, show_name=False, colorize=True, **kwargs): return output + if script_args.addr: results = IPWhoisCLI( @@ -1452,8 +1437,7 @@ def lookup_whois(self, hr=True, show_name=False, colorize=True, **kwargs): ) else None, proxy_https=script_args.proxy_https if ( script_args.proxy_https and len(script_args.proxy_https) > 0 - ) else None, - allow_permutations=(not script_args.disallow_permutations) + ) else None ) if script_args.whois: From 6a76d49426c5a0e774d2a392ba31aa1110440ed1 Mon Sep 17 00:00:00 2001 From: secynic Date: Wed, 30 Jan 2019 23:05:52 -0600 Subject: [PATCH 10/14] Updated docs for allow_permutations default of False --- ipwhois/ipwhois.py | 2 +- ipwhois/net.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ipwhois/ipwhois.py b/ipwhois/ipwhois.py index 26b8acb..9c9ff9b 100644 --- a/ipwhois/ipwhois.py +++ b/ipwhois/ipwhois.py @@ -44,7 +44,7 @@ class IPWhois: proxy support. Defaults to None. allow_permutations (:obj:`bool`): Allow net.Net() to use additional methods if DNS lookups to Cymru fail. *WARNING* deprecated in - favor of new argument asn_methods. Defaults to True. + favor of new argument asn_methods. Defaults to False. """ def __init__(self, address, timeout=5, proxy_opener=None, diff --git a/ipwhois/net.py b/ipwhois/net.py index 1e5b9d7..a5ed06a 100644 --- a/ipwhois/net.py +++ b/ipwhois/net.py @@ -105,7 +105,7 @@ class Net: proxy support. Defaults to None. allow_permutations (:obj:`bool`): Allow net.Net() to use additional methods if DNS lookups to Cymru fail. *WARNING* deprecated in - favor of new argument asn_methods. Defaults to True. + favor of new argument asn_methods. Defaults to False. Raises: IPDefinedError: The address provided is defined (does not need to be From d349b4a580196a7ec56b667ca5a375acbf53f346 Mon Sep 17 00:00:00 2001 From: secynic Date: Fri, 1 Feb 2019 18:13:28 -0600 Subject: [PATCH 11/14] Version increment (1.1.0) --- CHANGES.rst | 4 ++-- ipwhois/__init__.py | 2 +- ipwhois/docs/source/conf.py | 4 ++-- ipwhois/net.py | 2 +- setup.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 77586a8..0a2ec4f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,8 +1,8 @@ Changelog ========= -1.1.0 (TBD) ------------ +1.1.0 (2019-02-01) +------------------ - Exceptions now inherit a new BaseIpwhoisException rather than Exception (#205 - Darkheir) diff --git a/ipwhois/__init__.py b/ipwhois/__init__.py index ad0ea34..947ebf9 100644 --- a/ipwhois/__init__.py +++ b/ipwhois/__init__.py @@ -26,4 +26,4 @@ from .net import Net from .ipwhois import IPWhois -__version__ = '1.0.0' +__version__ = '1.1.0' diff --git a/ipwhois/docs/source/conf.py b/ipwhois/docs/source/conf.py index 2b6c290..aa54c1f 100644 --- a/ipwhois/docs/source/conf.py +++ b/ipwhois/docs/source/conf.py @@ -67,9 +67,9 @@ # built documents. # # The short X.Y version. -version = '1.0.0' +version = '1.1.0' # The full version, including alpha/beta/rc tags. -release = '1.0.0' +release = '1.1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/ipwhois/net.py b/ipwhois/net.py index a5ed06a..8ec3b15 100644 --- a/ipwhois/net.py +++ b/ipwhois/net.py @@ -223,7 +223,7 @@ def lookup_asn(self, *args, **kwargs): """ Temporary wrapper for IP ASN lookups (moved to asn.IPASN.lookup()). This will be removed in a future - release (1.0.0). + release. """ from warnings import warn diff --git a/setup.py b/setup.py index 090e821..9103dec 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ import io NAME = 'ipwhois' -VERSION = '1.0.0' +VERSION = '1.1.0' AUTHOR = 'Philip Hane' AUTHOR_EMAIL = 'secynic@gmail.com' DESCRIPTION = 'Retrieve and parse whois data for IPv4 and IPv6 addresses.' From 41557f066e6289f4b081877e3bbc2b6786b2c275 Mon Sep 17 00:00:00 2001 From: secynic Date: Fri, 1 Feb 2019 18:15:43 -0600 Subject: [PATCH 12/14] copyright update (1.1.0) --- LICENSE.txt | 2 +- ipwhois/__init__.py | 2 +- ipwhois/asn.py | 2 +- ipwhois/docs/source/conf.py | 2 +- ipwhois/exceptions.py | 2 +- ipwhois/experimental.py | 2 +- ipwhois/hr.py | 2 +- ipwhois/ipwhois.py | 2 +- ipwhois/net.py | 2 +- ipwhois/nir.py | 2 +- ipwhois/rdap.py | 2 +- ipwhois/scripts/docs/generate_examples.py | 2 +- ipwhois/scripts/ipwhois_cli.py | 2 +- ipwhois/scripts/ipwhois_utils_cli.py | 2 +- ipwhois/utils.py | 2 +- ipwhois/whois.py | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index d3e11d7..0da70ec 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2013-2017 Philip Hane +Copyright (c) 2013-2019 Philip Hane All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/__init__.py b/ipwhois/__init__.py index 947ebf9..440666f 100644 --- a/ipwhois/__init__.py +++ b/ipwhois/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/asn.py b/ipwhois/asn.py index 2a7e563..03946fe 100644 --- a/ipwhois/asn.py +++ b/ipwhois/asn.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/docs/source/conf.py b/ipwhois/docs/source/conf.py index aa54c1f..164be02 100644 --- a/ipwhois/docs/source/conf.py +++ b/ipwhois/docs/source/conf.py @@ -60,7 +60,7 @@ # General information about the project. project = 'ipwhois' -copyright = '2013-2017, Philip Hane' +copyright = '2013-2019, Philip Hane' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/ipwhois/exceptions.py b/ipwhois/exceptions.py index 42749b7..066814a 100644 --- a/ipwhois/exceptions.py +++ b/ipwhois/exceptions.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/experimental.py b/ipwhois/experimental.py index 2dd4262..a048bdf 100644 --- a/ipwhois/experimental.py +++ b/ipwhois/experimental.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Philip Hane +# Copyright (c) 2017-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/hr.py b/ipwhois/hr.py index 889e871..b51196e 100644 --- a/ipwhois/hr.py +++ b/ipwhois/hr.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/ipwhois.py b/ipwhois/ipwhois.py index 9c9ff9b..4a4d56b 100644 --- a/ipwhois/ipwhois.py +++ b/ipwhois/ipwhois.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/net.py b/ipwhois/net.py index 8ec3b15..8793921 100644 --- a/ipwhois/net.py +++ b/ipwhois/net.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/nir.py b/ipwhois/nir.py index bb4f0c9..910b4f8 100644 --- a/ipwhois/nir.py +++ b/ipwhois/nir.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/rdap.py b/ipwhois/rdap.py index b6ff5f5..9bccbe1 100644 --- a/ipwhois/rdap.py +++ b/ipwhois/rdap.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/scripts/docs/generate_examples.py b/ipwhois/scripts/docs/generate_examples.py index d271912..68e2137 100644 --- a/ipwhois/scripts/docs/generate_examples.py +++ b/ipwhois/scripts/docs/generate_examples.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/scripts/ipwhois_cli.py b/ipwhois/scripts/ipwhois_cli.py index ef957e3..5a06e9a 100644 --- a/ipwhois/scripts/ipwhois_cli.py +++ b/ipwhois/scripts/ipwhois_cli.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/scripts/ipwhois_utils_cli.py b/ipwhois/scripts/ipwhois_utils_cli.py index 2b707c6..7f86b95 100644 --- a/ipwhois/scripts/ipwhois_utils_cli.py +++ b/ipwhois/scripts/ipwhois_utils_cli.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/utils.py b/ipwhois/utils.py index 41edc04..1df4a91 100644 --- a/ipwhois/utils.py +++ b/ipwhois/utils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/ipwhois/whois.py b/ipwhois/whois.py index fb2bfe2..882dd90 100644 --- a/ipwhois/whois.py +++ b/ipwhois/whois.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2017 Philip Hane +# Copyright (c) 2013-2019 Philip Hane # All rights reserved. # # Redistribution and use in source and binary forms, with or without From 9dac9d2d4b4295075569d253fcc732186ac28112 Mon Sep 17 00:00:00 2001 From: secynic Date: Fri, 1 Feb 2019 18:18:10 -0600 Subject: [PATCH 13/14] add deprecation warnings comment --- UPGRADING.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/UPGRADING.rst b/UPGRADING.rst index 3fdca30..679db1a 100644 --- a/UPGRADING.rst +++ b/UPGRADING.rst @@ -17,6 +17,7 @@ v1.1.0 - Removed support for Python 2.6/3.3, added support for 3.7 - Removed the disallow_permutations argument from ipwhois_cli.py. Use ans_methods instead. +- Fixed deprecation warnings in core code ****** v1.0.0 From 1f1f8d78b8a977de999cd3bd1a7dd9ef2b200974 Mon Sep 17 00:00:00 2001 From: secynic Date: Fri, 1 Feb 2019 18:24:31 -0600 Subject: [PATCH 14/14] remove coverage statement --- README.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 2442df5..eca1a08 100644 --- a/README.rst +++ b/README.rst @@ -49,7 +49,6 @@ Features * Useful set of utilities * Experimental bulk query support * BSD license -* 100% core code coverage (See '# pragma: no cover' for exclusions) * Human readable field translations * Full CLI for IPWhois with optional ANSI colored console output. @@ -174,7 +173,7 @@ Input | allow_permutations | bool | Allow net.Net() to use additional methods if | | | | DNS lookups to Cymru fail. *WARNING* | | | | deprecated in favor of new argument | -| | | asn_methods. Defaults to False. | +| | | asn_methods. Defaults to False. | +--------------------+--------+-----------------------------------------------+ RDAP (HTTP)