Skip to main content

Get geolocation from IP address or hostname

Project description

Get geolocation information from IP address or hostname. Uses: ‘ip-api.com’, ‘freegeoip.net’ or ‘ipinfo.io’.

Simple example:

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

Please note the following:

The script by default will pause 0.5s between each request when doing multiple lookups using an input file. This is done to comply to the restrictions on ‘ip-api.com’ and ‘freegeoip.net’. Just be careful when using ‘ipinfo.io’.

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

Usage

Usage: ip2geo [ip|hostname] [options]

get geolocation from IP address or hostname, can use: 'ip-api.com',
'freegeoip.net' or 'ipinfo.io'

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' or
                'ipinfo'(default: ipapi)
-s SLEEP        time to sleep between requests (default: 0.5)
-t TIMEOUT      timeout in seconds to wait for reply (default: 5)
-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 ‘freegeoip.net’ api:

$ ip2geo google.com -g freegeoip

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

Notes

  • Works on Python 2

  • Tested on Linux and Windows, but should work on all platforms

  • Uses only Python standard library for maximum compatibility

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.2.tar.gz (4.6 kB view hashes)

Uploaded Source

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