Skip to main content

IP Whois Resolution and Parsing

Project description

ipwhois is a simple package for retrieving and parsing whois data for IPv4 and IPv6 addresses. This code was quickly thrown together to demonstrate functionality, and is by no means optimized or fully featured.

This version requires Python 3.3+ (for the ipaddress library) and dnspython3. Other Python version support is planned.

Usage Examples

Typical usage:

>>>> import ipwhois
>>>> from pprint import pprint

>>>> obj = ipwhois.IPWhois("")
>>>> results = obj.lookup(False)
>>>> pprint(results)

'asn': '15169',
    'asn_cidr': '',
    'asn_country_code': 'US',
    'asn_date': '2007-03-13',
    'asn_registry': 'arin',
    'nets': [{'cidr': '',
              'city': 'Mountain View',
              'country': 'US',
              'description': 'Google Inc.',
              'name': 'GOOGLE',
              'state': 'CA'}],
    'query': '',
    'raw': None


>>>> import ipwhois

>>>> countries = ipwhois.get_countries()
>>>> obj = ipwhois.IPWhois("")
>>>> results = obj.lookup(False)
>>>> print(countries[results['nets'][0]['country']])

United States


Parsing is currently limited to CIDR, country, description, name, and state 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 ‘, ‘.

Sometimes, you will see whois information with multiple consecutive same name fields, e.g., Description: some text\nDescription: more text. The parser will recognize this and the returned result will have these separated by ‘\n’.

Future Plans

IPWhois.httplookup() - Allow parsing of Whois data via RWS feeds from the various NICs. This feature is useful when outbound port 43 is not available. Only ARIN and RIPE have Whois-RWS services at the time of this writing. Although RIPE does have a feature that integrates the other NICs, they are limited on the types of information that is allowed to be displayed. Additionally, as part of this feature, proxy support will also be added.


0.1.4 (2013-09-12)

  • Added validity checks for the asn_registry value due to a bug in the Team Cymru ASN lookup over night.
  • Added timeout argument to IPWhois(). This is the default timeout in seconds for socket connections.
  • Fixed decoding issue in IPWhois.get_whois().

0.1.3 (2013-09-11)

  • Added exception handling with query retry support for socket errors, timeouts, connection resets.
  • Moved ASN queries to their own functions (IPWhois.get_asn_dns() and IPWhois.get_asn_whois())
  • Moved whois query to its own function (IPWhois.get_whois())
  • Country codes are now forced as upper case in the return dictionary.

0.1.2 (2013-09-10)

  • Fixed file path for get_countries().
  • Fixed variable names that conflicted with builtins.
  • Added content to README.
  • Moved CHANGES.txt to CHANGES.rst and added to
  • Download URL now points to GitHub master tarball.

0.1.1 (2013-09-09)

  • Fixed README issue.

0.1.0 (2013-09-06)

  • Initial release.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ipwhois, version 0.1.4
Filename, size File type Python version Upload date Hashes
Filename, size (15.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page