Skip to content

Commit

Permalink
Merge pull request #8 from secynic/rws
Browse files Browse the repository at this point in the history
Rws bug fixes
  • Loading branch information
secynic committed Sep 16, 2013
2 parents 0ab4148 + c73dcd1 commit 8f9c506
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

0.1.7 (2013-09-16)
------------------

- Fixed bug in set_proxy().
- Removed ARIN top level network entries from return dictionary of IPWhois.lookup_rws().
- Fixed bug in ARIN RWS parsing when only one network.

0.1.6 (2013-09-16)
------------------

Expand Down
16 changes: 4 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Typical usage::
>>>> from pprint import pprint
>>>> obj = ipwhois.IPWhois('74.125.225.229')
>>>> results = obj.lookup(False)
>>>> results = obj.lookup()
>>>> pprint(results)
{
Expand All @@ -42,7 +42,7 @@ REST (HTTP)::
>>>> from pprint import pprint
>>>> obj = ipwhois.IPWhois('74.125.225.229')
>>>> results = obj.lookup_rws(False)
>>>> results = obj.lookup_rws()
>>>> pprint(results)
{
Expand All @@ -51,15 +51,7 @@ REST (HTTP)::
'asn_country_code': 'US',
'asn_date': '2007-03-13',
'asn_registry': 'arin',
'nets': [{'address': '3635 Concorde Parkway\nSuite 200',
'cidr': '74.0.0.0/8',
'city': 'Chantilly',
'country': 'US',
'description': 'American Registry for Internet Numbers',
'name': 'NET74',
'postal_code': '20151',
'state': 'VA'},
{'address': '1600 Amphitheatre Parkway',
'nets': [{'address': '1600 Amphitheatre Parkway',
'cidr': '74.125.0.0/16',
'city': 'Mountain View',
'country': 'US',
Expand Down Expand Up @@ -112,7 +104,7 @@ Latest version from GitHub::
Parsing
=======

Parsing is currently limited to CIDR, country, description, name, state, city, address, and postal_code fields. This is assuming that those fields are present.
Parsing is currently limited to CIDR, country, name, description, state, city, address, and postal_code fields. This is assuming that those fields are present.

Some IPs have parent networks listed. The parser attempts to recognize this, and break the networks into individual dictionaries. If a single network has multiple CIDRs, they will be separated by ', '.

Expand Down
19 changes: 15 additions & 4 deletions ipwhois/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__version__ = '0.1.6'
__version__ = '0.1.7'

import ipaddress, socket, dns.resolver, re, json
from xml.dom.minidom import parseString
Expand Down Expand Up @@ -123,8 +123,9 @@ def set_proxy(host = None, port = '80', username = None, password = None):
#Define the host URL from the host and port.
url = 'http://' + host + ':' + port + '/'

#Create the proxy handler.
#Create the proxy handler and auth handler.
handler = request.ProxyHandler({'http': url})
auth_handler = None

#If the proxy username and password are defined.
if username is not None and password is not None:
Expand Down Expand Up @@ -908,7 +909,7 @@ def lookup_rws(self, inc_raw = False):
if not response:

response = self.get_rws('http://apps.db.ripe.net/whois/grs-search?query-string={0}&source=radb-grs'.format(self.address_str))

#If the inc_raw parameter is True, add the response to the return dictionary.
if inc_raw:

Expand All @@ -932,8 +933,18 @@ def lookup_rws(self, inc_raw = False):

try:

for n in response['nets']['net']:
net_list = response['nets']['net']

if not isinstance(net_list, list):

net_list = [net_list]

for n in net_list:

if 'orgRef' in n and n['orgRef']['@handle'] in ('ARIN', 'VR-ARIN'):

continue

addrs = []
addrs.extend(ipaddress.summarize_address_range(ipaddress.ip_address(n['startAddress']['$'].strip()), ipaddress.ip_address(n['endAddress']['$'].strip())))

Expand Down

0 comments on commit 8f9c506

Please sign in to comment.