(o o)
____________ooO_( )_Ooo_______________________________a_m_o_x___
____ ___ ____
/ ___| ___ ___|_ _| _ \
| | _ / _ \/ _ \| || |_) |
| |_| | __/ (_) | || __/
\____|\___|\___/___|_|
Find the geolocation of an IP address
from command-line
After a long search on the Internet - my wish seams to be that of
many - I finally found, among many others, GeoIPLookup.io and its
corresponding API.
To use the API we need to install CURL, the command-line downloader
and JQ, a command-line tool to process the JSON data from the API.
For Ubuntu/Debian:
$ sudo apt update
$ sudo apt install curl jq
Show geolocation data for your own public IP in json format:
$ curl
https://json.geoiplookup.io
{
"ip": "88.xx.xx.xx",
"isp": "HIGHWAY194",
"org": "High Speed Internet Customers",
"hostname": "88-xx-xx-xx.adsl.highway.telekom.at",
"latitude": 48.2235,
"longitude": 16.3987,
"postal_code": "1020",
"city": "Vienna (Leopoldstadt)",
"country_code": "AT",
"country_name": "Austria",
"continent_code": "EU",
"continent_name": "Europe",
"region": "Vienna",
"district": "Vienna",
"timezone_name": "Europe\/Vienna",
"connection_type": "Cable\/DSL",
"asn_number": 8447,
"asn_org": "A1 Telekom Austria AG",
"asn": "AS8447 - A1 Telekom Austria AG",
"currency_code": "EUR",
"currency_name": "Euro",
"success": true,
"premium": false
}
For output only the IP and country use JQ:
$ curl
https://json.geoiplookup.io | jq '.ip, .country_name'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 720 0 720 0 0 5070 0 --:--:-- --:--:-- --:--:-- 5070
"88.xx.xx.xx"
"Austria"
To get rid of the progress info of CURL use '-s' option and to eliminate
the quotes of JQ data use '-r' option:
$ curl -s
https://json.geoiplookup.io | jq -r '.ip, .country_name'
88.xx.xx.xx
Austria
To check a foreign IP:
$ curl -s
https://json.geoiplookup.io/8.8.8.8 | jq -r '.country_name'
United States
For more information take a look at:
->
https://geoiplookup.io/api
___________________________________________________2022_06_26___