Skip to main content

Lookup country code (iso 3166) by IP address.

Project description

travis coveralls pypibadge

About

Lookup country code (iso 3166) by IP address.

Install

$ pip install ip2country

Or

$ python setup.py install

How to use

First: Implement IStore Interface

You must implement IStore interface in ip2country/interfaces.py.

There is a sample implementation in example/store. This implementation is stored all records on the system memory.

Second: Store the records

store = Store()
parser = Parser(store)
with open(RECORD_FILE) as fp:
    parser.do(fp)

See examples/lookup.py:load for more detail.

Third: Lookup the IPAddress

store = Store()
record = store.lookup(IP_ADDRESS)
if record is None:
    print('Record not found')
else:
    print('{0} is allocated to {1}'.format(IP_ADDRESS, record.cc))

See examples/lookup.py:main for more detail.

Run the tests

$ tox

License

ip2country is licensed under the MIT LICENSE. See ./LICENSE.rst.

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 ip2country, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size ip2country-0.1.1-py2-none-any.whl (7.1 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size ip2country-0.1.1-py3-none-any.whl (7.0 kB) File type Wheel Python version 3.3 Upload date Hashes View
Filename, size ip2country-0.1.1.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page