Find out how to Discover Linux Server Geographic Location in Terminal
On this article, we are going to present you tips on how to discover the IP tackle geographic location of a distant Linux system utilizing open APIs and a easy bash script from the command line.
On the web, every server has a public-facing IP tackle, which is assigned on to the server or through a router that sends community visitors to that server.
IP addresses present a simple method to observe the situation of the server on the planet through the use of two helpful APIs supplied by ipinfo.io and ipvigilante.com to get the metropolis, state, and nation related with a server.
Set up Curl and jq
To get the IP tackle geographic location of the server, we have to set up curl command line downloader and jq command-line device to course of the JSON information from the geolocation APIs.
$ sudo apt set up curl jq #Ubuntu/Debian
$ sudo yum set up curl jq #CentOS/RHEL
$ sudo dnf set up curl jq #Fedora 22+
$ sudo zypper set up curl jq #openSUSE
Discover the Server’s Public IP Handle
To get the server’s public IP tackle, use the next curl command to make an API request to ipinfo.io in your terminal as proven.
$ curl https://ipinfo.io/ip
Get IP Location Knowledge From The API
After getting acquired the server public IP tackle, now you can make a request to ipvigilante.com‘s API to fetch the geolocation information utilizing the next command. Make sure that to switch with the server’s public IP.
$ curl https://ipvigilante.com/
That is the information we get from the above command.
Automate API Name utilizing Bash Script
Now to automate the API course of, we are going to create a script known as getipgeoloc.sh (you possibly can title it something you need) utilizing any of your favourite command line editors.
$ vim getipgeoloc.sh
Then copy and paste the next lengthy command in it.
curl -s https://ipvigilante.com/$(curl -s https://ipinfo.io/ip) | jq ‘.information.latitude, .information.longitude, .information.city_name, .information.country_name’
Save the file and make the script executable with the next command.
$ chmod +x getipgeoloc.sh
Lastly, run the script to get your Linux IP geographical location as proven within the following screenshot.
The above script reveals the metropolis and nation title together with the approximate latitude and longitude coordinates.
Alternatively, you too can run the above command with out saving it in a script as proven.
$ curl -s https://ipvigilante.com/$(curl -s https://ipinfo.io/ip) | jq ‘.information.latitude, .information.longitude, .information.city_name, .information.country_name’
You may additionally wish to learn these following associated articles:
four Methods to Discover Server Public IP Handle in Linux Terminal
Discover Out All Stay Hosts IP Addresses Related on Community in Linux
Discover Prime 10 IP Addresses Accessing Your Apache Internet Server
That’s it for now! On this quick article, we’ve proven tips on how to get your Linux IP geographic location from the terminal utilizing the curl and jq instructions. Share your ideas with us or ask any questions through the suggestions kind beneath.