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.
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 geolocate
or if you prefer, you also install from github via cargo install --git https://github.com/westernwontons/geolocate
. 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 .
To fetch geolocation data 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:
Long form is --name
, short is -n
.\
Currently, this can either be ipgeolocation
or ip2location
.\
default
value is ip2location
if you choose to not supply it.\
It tells geolocate
which API to hit.
Long form is --ip
, short is -i
.\
This is the IP address you want to fetch geolocation data about.
Long form is --key
, short is -k
.\
This is your API key for the respective service.\
geolocate
caches the api key
that you provide it and associates it with the provider's name.\
You can also give it a default with -d
or --default
Long form is --default
, short is -d
.\
This is the default provider you want geolocate
to hit when you only pass the IP address to hit.
Updating the default value is done like so:
geolocate -d <ip2location | ipgeolocation>
Any other value will result in an error message. As I add more providers this will surely change.\ (and as I get better at Rust)
If you have jq
on your system, you can pipe the returned JSON data there for pretty colors: geolocate -k api_key | jq
.
If you wish to do this via a bash
function, paste the lines below into your .zshrc, .bashrc
or whichever shell you use:
```bash
geoloc() { if [[ -z $1 ]]; then geolocate --help
else
geolocate "$@" 2>&1 | jq
fi
} ```
Now run source $HOME/.zshrc
, source $HOME/.bashrc
or whatever is the name of your prefered shell or just quit and reopen your terminal.
I banged this app out in a weekend and only tested it on a mac so I really don't know. If there are any ideas to improve the software and extend compatibility with Linux systems and possibly even Windows, open an issue or feature request.