Easily get the country code from an ip address.
Project description
location_ipfire_db_reader
Introduction
I was looking for a geo-ip library where I can easily convert IPs into countries. And this preferably in Python and preferably offline.
Couldn't find any, but ipfires location
utility came very close. Sadly it was coded in C.
That's why I re-interpreted the location databases structure into Python and made a tiny wrapper around it for easy access.
Installation:
pip install -U location-ipfire-db-reader
Main usage:
from location_ipfire_db_reader import LocationDatabase
# This call will _download the location database into the provided file.
# It will not re-_download it if there are no updates.
db = LocationDatabase('location.db')
print(db.find_country('8.8.8.8')) # US
This library should work for both IP4 & IP6.
Developers information
(or more accurately named: information for myself at a future point in time 😎)
decompress_db.py
contains just the code to facilitate extraction of the databasedownload_db.py
: download (or update) once a day the newest ipfire location database.database.py
: The wrapper (consumer-facing code) around the filehandling and reading and stuff.interpret_location_db.py
: contains the low-level interpretation of the database file.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file location_ipfire_db_reader-1.0.4.tar.gz
.
File metadata
- Download URL: location_ipfire_db_reader-1.0.4.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.9.18 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dbb4c21cafcc5e87c189f6ce45a7892d23f579bb66b7728efb9119b7cd567a0 |
|
MD5 | 092662e7f207b28425c9b2347fd39ebe |
|
BLAKE2b-256 | 2ffc9923241ed2c242021b4ddf03334b012a8ec4f101716cd2a3060418fce0b1 |
File details
Details for the file location_ipfire_db_reader-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: location_ipfire_db_reader-1.0.4-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.9.18 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44a6c559b6b84380ea78018e365ed2fb7199612c7d25967ee2696714443718bb |
|
MD5 | 5ce12abe4e281da68bea9b4d306ad14e |
|
BLAKE2b-256 | 3d43036b8664804ff0ace9a8ff3400f90b92ebdc3c35d6c7dc82d98fb84e79d0 |