Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
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.
Install the module from PyPI:
python3 -m pip install 2ip
The following methods are available.
When initialising the 2ip module the following parameters may be specified:
key
: The API key to use for lookups. If no API key defined the API lookups will use the rate limited free API.The geographic lookup method accepts the following parameters:
ip
: The IP address to lookup.format
{json,xml}: The output format for the request. json
will return a dict and xml
will return a string.force
{True,False}: Force an API lookup even if there is a cache entry.cache
{True,False}: Allow the lookup result to be cached.The provider lookup method accepts the following parameters:
ip
: The IP address to lookup.format
{json,xml}: The output format for the request. json
will return a dict and xml
will return a string.force
{True,False}: Force an API lookup even if there is a cache entry.cache
{True,False}: Allow the lookup result to be cached.Some example scripts are included in the examples directory.
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>'
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>'
FAQs
2ip.me API Client.
We found that 2ip demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.