Geolocate

Overview

The geolocate program uses https://ipgeolocation.io or https://ip2location.io API to fetch geolocation data of a given IP (IPv4) address. The data returned by the API is in JSON format.

Install

The easiest way to install the geolocate program is via cargo. If you have cargo installed on your system, you can simply run cargo install --git https://github.com/westernwontons/geolocate in a terminal. I would also recommend topgrade if you haven't heard of it.

In case you do not have cargo on your system, you can get it from the official site .

Usage

To fetch geodata from an IP address you first need to create an account at https://ipgeolocation.io/signup.html and/or https://ip2location.io to get an API key. There's a free tier on both sites. geolocate has the following CLI arguments:

Name

Long form is --name, short is -n.\ Currently, this can either be ipgeolocation or ip2location.\ default value is ipgeolocation if you choose to not supply it.\ It tells geolocate which API to hit.\

IP

Long form is --ip, short is -i.\ This is the IP address you want to fetch geolocation data about.\

API Key

Long form is --key, short is -k.\ This is your API key for the respective service.\ If you don't want to always type it out, you can also slap it in an environment variable.\ Currently, geolocate looks for these two values: * IP_GEOLOCATION_DOT_IO_API_KEY * IP_2_LOCATION_DOT_IO_API_KEY

If you have both of them saved and don't give a --name parameter, geolocate will default to hit https://ipgeolocation.io.\ I suggest saving them in environment variables, makes it easier to use.

Formatting

If you have jq on your system, you can pipe the returned JSON data there for pretty colors: geolocation IP -k API_Token | jq.

If you wish to do this via bash function, paste the below lines into your .zshrc, .bashrc or whichever shell you use: ```bash

geolocate

geoloc() { if [[ -z $1 ]]; then geolocate --help

else
    geolocate "$@" 2>&1 | jq
fi

} ```

Save and exit the file. Now you either restart your terminal session or simply reload the .*rc file with the source ~/.*rc command. Please note, that for the function to work you have to have at least one of the tokens saved into an environment variable.