How To Get Your Geolocation From Commandline In Linux
This brief tutorial will walk you through how to get your geolocation from commandline in Linux. This could be useful if you wanted to know the location of your VPS or remote servers. A fellow Linux user Rafael Rinaldi has created a handy tool called “whereami” to find out the geolocation information using freegeoip.net from the commandline. Please note that some hosting providers might have hidden their server’s exact place, or faked it due to security reasons. In such cases, this tool won’t help.
Now, let us get started to find out the geolocation of the Linux system from commandline using whereami utility.
Get Your Geolocation From Commandline In Linux
To install npm on RPM based systems such as RHEL, CentOS, Fedora, run the following commands:
sudo yum install epel-release
sudo yum install npm
sudo dnf install epel-release
sudo dnf install npm
On Debian, Ubuntu, Linux Mint, run:
sudo apt-get install npm
On Arch Linux and its derivatives:
sudo pacman -S npm
sudo zypper install npm
Once npm installed, run the following command to install “whereami” tool.
npm install -g @rafaelrinaldi/whereami
You will get an output something like below.
/usr/bin/whereami -> /usr/lib/node_modules/@rafaelrinaldi/whereami/bin/whereami /usr/lib └─┬ @rafaelrinaldi/[email protected] ├─┬ [email protected] │ ├─┬ [email protected] │ │ └── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ └─┬ [email protected] │ └── [email protected] ├─┬ [email protected] │ └─┬ [email protected] │ ├── [email protected] │ └─┬ [email protected] │ └─┬ [email protected] │ ├── [email protected] │ └── [email protected] ├── [email protected] ├─┬ [email protected] │ └── [email protected] └── [email protected]
Find Your Geolocation
Now, it’s play time. To know your location, simply run:
Sample output would be:
As you see in the above output, It displays the latitude (11.1), and longitude (77.35) of my location.
I don’t understand, can I have a human-readable format? Of course, you can! Add –f human switch with whereami command like below.
whereami --f human
Here is my output:
Tiruppur, Tamil Nadu, India
I wouldn’t say this is an accurate result, but it was very close to my actual location.
I need more details, can I have that too? Yes! Display the raw result that contains the public IP address, country code, zip code, metro code time zone etc., using the following command:
To know more details about whereami command, run:
Usage: whereami [OPTIONS] Get your geolocation information using freegeoip.net from the CLI Example: $ whereami -23.4733,-46.6658 $ whereami --f human San Francisco, CA, United States Options: -v --version Display current software version -h --help Display help and usage details -f --format Output format (either human, json or sexagesimal) -r --raw Output raw data from freegeoip.net
I am pretty sure there could be other tools and ways to find out the geolocation. D you know any other methods? Please enlighten me in the comment section below.
Hope this helps. I will be soon here with another useful guide. If you find guide useful, please share it on your social networks and support OSTechNix.
Happy weekend! Cheers!!
Thanks for stopping by!
How can I benefit from this blog:
- Subscribe to our Email Newsletter : Sign Up Now
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Facebook | Twitter | Google Plus | LinkedIn | RSS feeds
Have a Good day!!