Skip to main content

Get geolocation from IP address or hostname

Project description

Downloads

ip2geo

Get geolocation information from IP address or hostname. Uses: ‘ip-api.com’, ‘freegeoip.net’, ‘ipinfo.io’ or ‘coding.tools’. Can also do a local lookup using DB-IP.com IP to City Lite MMDB Database.

Simple example:

$ ip2geo 8.8.8.8
8.8.8.8 - United States (US), California (CA), Mountain View - Google

Local lookup:

$ ip2geo 8.8.8.8 -d dbip-city-lite.mmdb
8.8.8.8 - United States (US), New Jersey, Newark

Please note the following:

The script by default will sleep 1.5s between each request when doing multiple lookups using an input file. This is done to comply to the restrictions on ‘ip-api.com’. The sleep time can be changed using the ‘-s’ switch.

Notes

  • Works on Python 2 and Python 3

  • Uses only Python standard library for remote lookup

Install

Install using pip:

pip install ip2geo

or

Download and set executable permission on the script file:

chmod +x ip2geo.py

or

Download and run using the python interpreter:

python ip2geo.py

For local lookup the maxminddb module is needed:

pip install maxminddb

Usage

Usage: ip2geo.py [ip|hostname] [options]

get geolocation from IP address or hostname, can use: 'ip-api.com',
'freegeoip.net', 'ipinfo.io', 'coding.tools' or 'db-ip.com' ip to city lite
database for local lookup

Options:
    --version         show program's version number and exit
    -h, --help        show this help message and exit
    -g API            geolocation api to use: 'ipapi', 'freegeoip', 'ipinfo' or
                      'coding'(default: ipapi)
    -s SLEEP          time to sleep between http requests (default: 1.5)
    -t TIMEOUT        timeout in seconds to wait for reply (default: 5)
    -d DATABASE_FILE  local lookup using db-ip.com ip to city lite database
                      mmdb: https://db-ip.com/db/download/ip-to-city-lite, the
                      maxminddb module must be installed:
                      https://github.com/maxmind/MaxMind-DB-Reader-python
    -i INPUT_FILE     use ips/hostnames from input file (one ip/hostname per
                      line)
    -o OUTPUT_FILE    save geolocation information to file

Examples

Get geolocation from IP or hostname:

$ ip2geo google.com

Get geolocation using ‘coding.tools’ api:

$ ip2geo google.com -g coding

Uses an input file containing multiple ips/hostnames (one per line):

$ ip2geo -i ips.txt

Save output to file:

$ ip2geo -i ips.txt -o geo_info.txt

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

ip2geo-0.4.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file ip2geo-0.4.tar.gz.

File metadata

  • Download URL: ip2geo-0.4.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for ip2geo-0.4.tar.gz
Algorithm Hash digest
SHA256 97c9ec0742d7a6d1e81e42b26fbbd88c51e733f2f7783420914641393da73c67
MD5 b043bdc849295dbe999a7ee45838c2a1
BLAKE2b-256 5cf2ba0e277aba8b03479a6243e6abba03638a9735fbd1fa99af773a6e9cec0e

See more details on using hashes here.

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