In our previous article, we saw how to get the geolocation info for an IP Address using bash, curl and jq in Linux. Let's see how the same can be done in Windows 10. We can use Bash on Linux or PowerShell for the same purpose.
Again, we will use the free service "freegeoip.net" as a source of the geolocation info. It provides a public HTTP API to search the geolocation of IP addresses. It uses a database of IP addresses that are associated with cities along with other relevant information like time zone, latitude and longitude. This is very useful.
Get Geolocation info of IP Address in Windows 10 using Bash on Ubuntu
If you have Bash on Linux installed, then you can use it in this case. You need to install the jq console JSON parser. Do it as follows.
- Open Bash on Ubuntu. You might need to install it first. See the following article:
How to enable Ubuntu Bash in Windows 10Tip: you can add Bash on Ubuntu to the Explorer's context menu to open it in any desired folder quickly.
- Type the following command:
sudo apt-get install jq
- Now, you can use the following command:
curl http://freegeoip.net/json/22.214.171.124>tmpjson.txt && jq '.' tmpjson.txt && rm tmpjson.txt
It is the same command I used in the native Linux environment, however, there is a glitch. In Windows 10, Bash on Ubuntu has broken support for pipeline output. Due to this issue, you cannot combine multiple tools to work together properly.
So I used a temporary file 'tmpjson.txt' which stores the server response and then gets deleted.
If you are not a user of Bash on Ubuntu, you can use PowerShell instead.
Get Geolocation info of IP Address in Windows 10 using PowerShell
Open a new instance of PowerShell as described here: All ways to open PowerShell in Windows 10
Instead of the curl tool, you can use the cmdlet Invoke-RestMethod. It is specially created to work with REST (Representational State Transfer) services which usually return JSON or XML data.
The syntax is as follows:
Invoke-RestMethod -Method Get -Uri http://freegeoip.net/json/126.96.36.199
The result of the command will be as follows:
You don't even need to apply additional formatting to the command. It is already nicely displayed in the output.