Skip to main content

=========== Geo IP

Provides a fast, seamless in memory ip to country functionality based on the ip2nation db.

  • No dependencies
  • Completely free
  • Country resolution only
  • Queries / sec > 13.5k per core
  • Data file can be refreshed without a restart
  • Memory footprint < 40 MB
  • Command line
  • Stream / pipe ips and get comma delimited [ip,2 letter country code] e.g. 12.12.12.12,US

Change log:

  • If you upgrade please note that there is a BREAKING CHANGE geoip module was renamed to xgeoip
  • Supports Python 2.7 / 3.x
  • ip2nation file updated to May 2020 version
#Python 2.7 / Python 3.x
from geoip import xgeoip
r = xgeoip.GeoIp()
r.load_memory()
r.resolve("12.12.12.12").country_code
#This prints : 'US'

print (r.resolve("123.44.57.4"))
#This prints : {'country': 'Korea (South)', 'host_name': '', 'country_code': 'KR'}

r.resolve2("133.12.12.12")
#This prints : 'JP'

Command line

package usage: python geoip/xgeoip.py resolve 1.1.1.1 {'country_code': 'AU', 'country': 'Australia', 'host_name': ''}

source usage: python xgeoip.py [-h] [-v] {download,resolve} ...

positional arguments: {download,resolve}

optional arguments: -h, --help show this help message and exit -v, --verbose increase output verbosity

usage: geoip.py resolve [-h] [-ho] [-s] [--stream] ip

positional arguments: ip The ip address to get the country for

optional arguments: -h, --help show this help message and exit -ho, --host When set to true the code will try to get the host name -s, --short When set to true the code will return a 2 letter country code only --stream When set to true the code expect a stream of ips

usage: geoip.py download [-h]

optional arguments: -h, --help show this help message and exit

Installation

pip install geoip2nation

PyPI: https://pypi.python.org/pypi/geoip2nation/

Github: https://github.com/avindak/python-geo-ip

ip2nation

  • Data can be downloaded using the download method

  • The load_memory method loads the ip2nation sql data file from disk into an in memory sqlite3 db

license

MIT

Links

Metadata

Release files for geoip2nation 0.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for geoip2nation 0.2.7
File Size Uploaded
geoip2nation-0.2.7.tar.gz 371.4 kB Details

Release files / geoip2nation-0.2.7.tar.gz

Download URL geoip2nation-0.2.7.tar.gz
Size 371.4 kB
Tags Source
SHA-256 checksum
How to use checksums
088525c31565ae863f791b449cc84d7b98ec0677bba52f1dc36d59c7ca6fcae8
BLAKE2b-256 checksum
How to use checksums
ca368acfdb78be3cbf518c15c39686804c5c777078a291494784c4723fcc106f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.2.7 This release

1 release file

0.2.6

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page