whereami – A small nifty tool to get your Geolocation information in Linux

Hey folks, today I got another interesting topic that allows you to get your geolocation information from the command line.

whereami is a small nifty tool which allows you to lookup IP addresses and get information about where that address is assigned using freegeoip.net written in JavaScript.

It could be very useful when you are investigating a suspicious email alert or if you want to know your remote server physical location.

What is npm

npm is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js.

npm is distributed with Node.js so when you install Node.js parallel npm get installed on your system automatically.

How to install whereami on Linux

There is no official distribution package for whereami but we can easily install on Linux distributions throgh npm.

For Debian/Ubuntu, use apt-get command or apt command to install nodejs & npm.

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt-get install -y nodejs

For RHEL/CentOS, use YUM Command to install nodejs & npm.

$ curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
$ sudo yum -y install nodejs

For Fedora, use dnf command to install nodejs & npm.

$ curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
$ sudo dnf -y install nodejs

For Arch Linux, use Pacman Command to install nodejs & npm.

$ pacman -S nodejs npm

For openSUSE, use Zypper Command to install nodejs & npm.

$ sudo zypper nodejs

Finally, Run the following pip command to install nodejs & npm.

$ sudo npm install -g @rafaelrinaldi/whereami

How to use whereami

Once you have installed the utility  just fire the whereami command alone to get your location. Unfortunately, the below output displays the latitude (12.98), and longitude (77.58) of my location which is not human readable.

$ whereami
12.9833,77.5833

Add -f option to get your location with human readable format.

$ whereami -f human
Bengaluru, Karnataka, India

To get more details (i mean raw data), including public IP address, country code, zip code, time zone, etc,., add -r option.

$ whereami -r
{"ip":"103.5.134.167","country_code":"IN","country_name":"India","region_code":"KA","region_name":"Karnataka","city":"Bengaluru","zip_code":"","time_zone":"Asia/Kolkata","latitude":12.9833,"longitude":77.5833,"metro_code":0}

If you want to know more option which is available for whereami, simply navigate to man page/help section.

$ whereami -h

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

One Comment on “whereami – A small nifty tool to get your Geolocation information in Linux”

  1. HI,

    I am trying to run wherami from inside a shell script linux :
    mypos=$(whereami)
    echo $mypos
    and then writes to a file
    echo “$(hostname) $(date ‘+Date: %a %m /%d / %y Time is: %R’) “WAN IP: “”$mypos $myip $1 >> logmail.txt

    works on the command line but not inside the shell.

    Any help would be appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *