diff --git a/CHANGES.rst b/CHANGES.rst index dcf5448..86d1abd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ------------------ diff --git a/README.rst b/README.rst index 45e5da6..df2d7fb 100644 --- a/README.rst +++ b/README.rst @@ -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. \ No newline at end of file +we need. The LACNIC RWS service is supported, but is in beta v2. This may +result in availability or performance issues. \ No newline at end of file diff --git a/ipwhois/ipwhois.py b/ipwhois/ipwhois.py index 73ad7ce..27209e2 100644 --- a/ipwhois/ipwhois.py +++ b/ipwhois/ipwhois.py @@ -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.+)$', 'country': '^(country):[^\S\n]+(?P.+)$', @@ -146,7 +146,8 @@ 'updated': '^(changed):[^\S\n]+(?P[0-9]{8}).*$' }, - 'dt_format': '%Y%m%d' + 'dt_format': '%Y%m%d', + 'dt_rws_format': '%Y%m%d' }, 'afrinic': { 'server': 'whois.afrinic.net', @@ -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: