Skip to content

Commit

Permalink
v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
secynic committed Nov 21, 2013
1 parent 1b501b3 commit fe370b4
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Changelog
=========

0.5.0 ()
0.5.0 (2013-11-20)
------------------

- Reformatting for PEP 8 compliance.
- Added LACNIC RWS support for IPWhois.lookup_rws().
- Added LACNIC RWS (Beta v2) support for IPWhois.lookup_rws().

0.4.0 (2013-10-17)
------------------
Expand Down
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ REST (HTTP)
===========

IPWhois.lookup_rws() should be faster than IPWhois.lookup(), but may not be as
reliable. APNIC, LACNIC, and AFRINIC do not have a Whois-RWS service yet. We
reliable. APNIC, and AFRINIC do not have a Whois-RWS service yet. We
have to rely on the Ripe RWS service, which does not contain all of the data
we need.
we need. The LACNIC RWS service is supported, but is in beta v2. This may
result in availability or performance issues.
111 changes: 108 additions & 3 deletions ipwhois/ipwhois.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
},
'lacnic': {
'server': 'whois.lacnic.net',
'url': ('http://apps.db.ripe.net/whois/grs-search?'
'query-string={0}&source=lacnic-grs'),
'url': ('http://restfulwhoisv2.labs.lacnic.net/'
'restfulwhois/ip/{0}'),
'fields': {
'description': '^(owner):[^\S\n]+(?P<val>.+)$',
'country': '^(country):[^\S\n]+(?P<val>.+)$',
Expand All @@ -146,7 +146,8 @@
'updated':
'^(changed):[^\S\n]+(?P<val>[0-9]{8}).*$'
},
'dt_format': '%Y%m%d'
'dt_format': '%Y%m%d',
'dt_rws_format': '%Y%m%d'
},
'afrinic': {
'server': 'whois.afrinic.net',
Expand Down Expand Up @@ -1015,6 +1016,110 @@ def lookup_rws(self, inc_raw=False, retry_count=3):

pass

elif results['asn_registry'] == 'lacnic':

try:

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

net = base_net.copy()
net['cidr'] = ', '.join([i.__str__()
for i in ipaddress.collapse_addresses(addrs)])

net['country'] = response['country'].strip()

events = response['events']

if not isinstance(events, list):

events = [events]

for ev in events:

if 'eventAction' in ev and 'eventDate' in ev:

if ev['eventAction'] == 'registration':

tmp = ev['eventDate'].strip()

value = datetime.strptime(
tmp,
NIC_WHOIS[
results['asn_registry']]['dt_rws_format']
).isoformat('T')

net['created'] = value

elif ev['eventAction'] == 'last changed':

tmp = ev['eventDate'].strip()

value = datetime.strptime(
tmp,
NIC_WHOIS[
results['asn_registry']]['dt_rws_format']
).isoformat('T')

net['updated'] = value

entities = response['entities']

if not isinstance(entities, list):

entities = [entities]

for en in entities:

if en['roles'][0] == 'registrant':

temp = en['vcardArray'][1]

for t in temp:

if t[0] == 'fn':

net['name'] = t[3].strip()

elif t[0] == 'org':

net['description'] = t[3][0].strip()

elif t[0] == 'adr':

net['address'] = t[1]['label'].strip()

elif t[0] == 'email':

net['misc_emails'] = t[3].strip()

elif en['roles'][0] == 'abuse':

temp = en['vcardArray'][1]

for t in temp:

if t[0] == 'email':

net['abuse_emails'] = t[3].strip()

elif en['roles'][0] == 'tech':

temp = en['vcardArray'][1]

for t in temp:

if t[0] == 'email':

net['tech_emails'] = t[3].strip()
nets.append(net)

except:

pass

else:

try:
Expand Down

0 comments on commit fe370b4

Please sign in to comment.