Python 2ip Module
2ip allows you to make requests to the 2ip.me API to retrieve provider/geographic information for IP addresses. Requests are (optionally, on by default) cached to prevent unnecessary API lookups when possible.
Installation
Install the module from PyPI:
python3 -m pip install 2ip
Methods
The following methods are available.
TwoIP (Initialisation)
When initialising the 2ip module the following parameters may be specified:
- Optional
key: The API key to use for lookups. If no API key defined the API lookups will use the rate limited free API.
geo
The geographic lookup method accepts the following parameters:
- Required
ip: The IP address to lookup. - Optional
format{json,xml}: The output format for the request.jsonwill return a dict andxmlwill return a string. - Optional
force{True,False}: Force an API lookup even if there is a cache entry. - Optional
cache{True,False}: Allow the lookup result to be cached.
provider
The provider lookup method accepts the following parameters:
- Required
ip: The IP address to lookup. - Optional
format{json,xml}: The output format for the request.jsonwill return a dict andxmlwill return a string. - Optional
force{True,False}: Force an API lookup even if there is a cache entry. - Optional
cache{True,False}: Allow the lookup result to be cached.
Examples
Some example scripts are included in the examples directory.
Provider API
Retrieve provider information for the IP address 192.0.2.0 as a dict:
>>> from twoip import TwoIP
>>> twoip = TwoIP(key = None)
>>> twoip.provider(ip = '192.0.2.0')
{'ip': '192.0.2.0',
'ip_range_end': '3221226239',
'ip_range_start': '3221225984',
'mask': '24',
'name_ripe': 'Reserved AS',
'name_rus': '',
'route': '192.0.2.0'}
Retrieve provider information for the IP address 192.0.2.0 as a XML string:
>>> from twoip import TwoIP
>>> twoip = TwoIP(key = None)
>>> twoip.provider(ip = '192.0.2.0', format = 'xml')
'<?xml version="1.0" encoding="UTF-8"?>\n<provider_api><ip>192.0.2.0</ip><name_ripe>Reserved AS</name_ripe><name_rus></name_rus><ip_range_start>3221225984</ip_range_start><ip_range_end>3221226239</ip_range_end><route>192.0.2.0</route><mask>24</mask></provider_api>'
Geographic API
Retrieve geographic information for the IP address 8.8.8.8 as a dict:
>>> from twoip import TwoIP
>>> twoip = TwoIP(key = None)
>>> twoip.geo(ip = '8.8.8.8')
{'city': 'Mountain view',
'country': 'United states of america',
'country_code': 'US',
'country_rus': 'США',
'country_ua': 'США',
'ip': '8.8.8.8',
'latitude': '37.405992',
'longitude': '-122.078515',
'region': 'California',
'region_rus': 'Калифорния',
'region_ua': 'Каліфорнія',
'time_zone': '-08:00',
'zip_code': '94043'}
Retrieve geographic information for the IP address 8.8.8.8 as a XML string:
>>> from twoip import TwoIP
>>> twoip = TwoIP(key = None)
>>> twoip.geo(ip = '8.8.8.8', format = 'xml')
'<?xml version="1.0" encoding="UTF-8"?>\n<geo_api><ip>8.8.8.8</ip><country_code>US</country_code><country>United states of america</country><country_rus>США</country_rus><country_ua>США</country_ua><region>California</region><region_rus>Калифорния</region_rus><region_ua>Каліфорнія</region_ua><city>Mountain view</city><latitude>37.405992</latitude><longitude>-122.078515</longitude><zip_code>94043</zip_code><time_zone>-08:00</time_zone></geo_api>'
Roadmap/Todo
- Support for email API
- Support for MAC address API
- Support for hosting API
- Option to retrieve data as XML
- Unit tests
- Deduplicate handler to retrieve information from API
Metadata
Release files for 2ip 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| 2ip-0.0.2.tar.gz | 7.1 kB | Without provenance | Details for 2ip-0.0.2.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| 2ip-0.0.2-py3.8.egg | Legacy Egg format | - | - | Details for 2ip-0.0.2-py3.8.egg |
| 2ip-0.0.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for 2ip-0.0.2-py2.py3-none-any.whl |
Total release size: 24.8 kB
Release files / 2ip-0.0.2.tar.gz
| Download URL | 2ip-0.0.2.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a96b35b095e0d3df119a781bbd7bca83450e80023865c1b0403aa2cc1863fe98
|
|
BLAKE2b-256 checksum How to use checksums |
22134df6660204dbe78cbe423076b442ebba088129416b229098332b50116639
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6
|
Release files / 2ip-0.0.2-py3.8.egg
| Download URL | 2ip-0.0.2-py3.8.egg |
|---|---|
| Size | 10.5 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
20207937f4609ee98ebc161be5e60bcb52fe416dbee5d869e7bfc3dfe54beb5e
|
|
BLAKE2b-256 checksum How to use checksums |
0de5e754526a04e14f34987af0c1bd01f5f606c5295f4f089817ee911e83a71b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6
|
Release files / 2ip-0.0.2-py2.py3-none-any.whl
| Download URL | 2ip-0.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d42c507baaa4744588866a34f43c5afffc6b320145d4707b7e045f3456b00f50
|
|
BLAKE2b-256 checksum How to use checksums |
22ea87670399af652d23d00561cfc451583102b7b5670cb6e285bb7820f1e35f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6
|
Security for 2ip 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.