Skip to main content

Get the geolocation of the current server

Project description

Get the geolocation of the current server

This package provides a command line utility to get the geolocation of the current server.

Installation

To install with conda do:

conda install whereisip

To install with pip do:

pip install whereisip

Requirements

  • Python 3.6+

  • appdirs

  • country_converter

  • geocoder

  • latloncalc

Python version

Tested for Python 3.6, 3.7, 3.8, 3.9, 3.10

Usage

Varying output format

You can simply run on the command line:

whereisip

This yields the location of the server you are currently logged into, e.g.:

>>> Server 37.97.253.1 @ Amsterdam/Netherlands (NL) has coordinates (52° 22′ 26.4″ N, 4° 53′ 22.9″ E)

Other output formats can be picked as well. If you only want the geo coordinates of the location of your server you can do:

whereisip --format sexagesimal

which yields:

>>> 52° 22′ 26.4″ N, 4° 53′ 22.9″ E

Or if you prefer to have a decimal representation of your server’s location you can do:

whereisip --format decimal

resulting in:

>>> 52.37, 4.89

To get the name of the location in stead of coordinates you can do:

whereisip --format human

which gives:

>>> Amsterdam/Netherlands (NL)

Note that you can copy-paste the sexagesimal representation 52° 22′ 26.4″ N, 4° 53′ 22.9″ E into google maps in order to show your location on the map.

More examples

This utility can be used to determine the distance of your server to your current location. For instance, if your are located in Amsterdam, NL and your are logged in onto the google server, you can do:

whereisip  --my_location Amsterdam,NL

Now, next to the location of your sever, also the distance to your location is given:

Server 8.8.8.8 @ Mountain View/United States (US) has coordinates (37° 24′ 20.2″ N, 122° 4′ 39.0″ W)
Distance from Amsterdam,NL (52° 22′ 21.9″ N, 4° 53′ 37.0″ E):  8816km.

You can also specify the server location in your are not logged into it like:

whereisip --ip 8.8.8.8 --my_location Amsterdam,NL

Note the your location does not need to be a server (but can be), but can be any address recognised by google. In case you specify another server and don’t specify your location, by default your location is set to the location of your current server. The distance is calculated based on this location.

Cache files

The whereisip script uses geocoder to retrieve the coordinates of a location and a server. All retrieved information is stored in cache files under $HOME/.cache/whereisip (for Linux). The next time you want to retrieve information on the same server or location, the cache file is read instead of making a new query to geocoder. In case you want to force to reset the cache files you can pass the –reset_cache option. In case you don’t want to use cache files at all, you can also pass –skip_cache option; this prevent to write any cache files at all.

Get Help

The help information can be shown with:

whereisip --help

which gives the full help:

usage: whereisip [-h] [--reset_cache] [--skip_cache]
                 [--n_digits_seconds N_DIGITS_SECONDS]
                 [--ip_address IP_ADDRESS] [--version]
                 [-f {sexagesimal,decimal,human,raw,full,short}] [-v] [-vv]
                 [--my_location <Location or IP>]

Get the location of your server (or any other server) and calculate the
distance to your own location

optional arguments:
  -h, --help            show this help message and exit
  --reset_cache         Reset the cache files located in the .cache directory.
                        Without reset, the informationis read from a cache
                        file instead of making a new request to geocoder. Each
                        IP address of location gets its own cache file.
                        (default: False)
  --skip_cache          Do not read of write to the cache files (default:
                        False)
  --n_digits_seconds N_DIGITS_SECONDS
                        Number of digits to use for the seconds notation. If a
                        decimal notation is used, the number of decimals will
                        be n_digit_seconds + 1 (default: 1)
  --ip_address IP_ADDRESS
                        The ip address to get the geo location from. If not
                        given, the local machine is used (default: None)
  --version             show program's version number and exit
  -f {sexagesimal,decimal,human,raw,full,short}, --format {sexagesimal,decimal,human,raw,full,short}
                        Format of the output. Choices are:
                         - decimal    : Decimal latitude/longitude (default)
                         - sexagesimal: Sexagesimal latitude/longitude
                         - human      : Human location City/Country
                         - full       : Full report with all location notations
                         - short      : A compact report with a sexagesimal and human nation + distance
                         - raw        : raw output from api
                         (default: short)
  -v, --verbose         set loglevel to INFO (default: None)
  -vv, --debug          set loglevel to DEBUG (default: None)
  --my_location <Location or IP>
                        Define the location of your device which is used to
                        calculate the distance to the server. A location can
                        be a 'cite,country' combination (or any other address
                        recognised by Google) or an IP address. In case no
                        location is given and the *ip_address* option is used
                        to specify an otherserver than your local server, my
                        location is set to you local server's IP address
                        (default: None)

Note

This project has been set up using PyScaffold 4.2.1. For details and usage information on PyScaffold see https://pyscaffold.org/.

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

whereisip-1.2.7.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

whereisip-1.2.7-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file whereisip-1.2.7.tar.gz.

File metadata

  • Download URL: whereisip-1.2.7.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for whereisip-1.2.7.tar.gz
Algorithm Hash digest
SHA256 e4d0395dc50cfb373ced60bb762208724d107c27f31884dc962eb3d21043b173
MD5 07d9a080cd127fc17746b66c2a6f352b
BLAKE2b-256 0acc99909d551f220ed2b2e77136afc78fd589e1e50eb302bb3f45fee615f65b

See more details on using hashes here.

File details

Details for the file whereisip-1.2.7-py3-none-any.whl.

File metadata

  • Download URL: whereisip-1.2.7-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for whereisip-1.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 52c1a5868a700cc9f48c42e2bdc1179e2a1303b72fd2be782299d561e5ca4fc6
MD5 76f933959443cbf8ea928dbfc4d67aa7
BLAKE2b-256 7e3e92e16f4762746243f8e40b411b54ddc165789e72c5efa1fbf91f086dff6c

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