Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dmitriiweb/ip-country
An offline tool to get country by IP
https://github.com/dmitriiweb/ip-country
ip ipv4 python
Last synced: 1 day ago
JSON representation
An offline tool to get country by IP
- Host: GitHub
- URL: https://github.com/dmitriiweb/ip-country
- Owner: dmitriiweb
- License: mit
- Created: 2019-08-17T09:36:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-19T10:16:17.000Z (over 5 years ago)
- Last Synced: 2024-11-12T10:17:42.813Z (2 months ago)
- Topics: ip, ipv4, python
- Language: Python
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ip-country
An offline tool to get country by IP## Requirements
- Python >= 3.6
- IP2Location™ LITE IP-COUNTRY-REGION-CITY Database## Installation
1. Download IP2Location database for IPv4 from [https://lite.ip2location.com/database/ip-country-region-city](here)
2. Install library:
```
pip install ip_country
```
## Usage
```
>>> from pprint import pprint
>>> from ip_country import IPCountry
>>> ip = IPCountry('/path/to/ipdb.csv')
>>> ip_data = ip.get_ip_data('13.73.96.0')
>>> pprint(ip_data)
{'city_name': 'Melbourne',
'country_code': 'AU',
'country_name': 'Australia',
'error': None,
'ip': '13.73.96.0',
'region_name': 'Victoria'}>>> ip_data = ip.get_ip_data('blah.73.96.0')
>>> pprint(ip_data)
{'error': "Only decimal digits permitted in 'blah' in 'blah.73.96.0'",
'ip': 'blah.73.96.0'}
```