Skip to main content

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 database
  • download_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

location_ipfire_db_reader-1.0.4.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

location_ipfire_db_reader-1.0.4-py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page