Gathering IP Geographic Information from CLI
I came across this one-liner to get geographic location information for the IP address being used from the Linux command line, and wanted to make a note of it for future use.
The Code and Results
Requires curl or wget as presented below, obviously with modification would work with other tools as well.
curl -s https://ifconfig.co/json|json_pp || wget -qO- https://ifconfig.co/json|json_pp
{
"asn" : "AS16433",
"asn_org" : "NCTC-ISP",
"city" : "Portland",
"country" : "United States",
"country_eu" : false,
"country_iso" : "US",
"ip" : "74.123.46.107",
"ip_decimal" : 1249586795,
"latitude" : 36.5686,
"longitude" : -86.5142,
"metro_code" : 659,
"region_code" : "TN",
"region_name" : "Tennessee",
"time_zone" : "America/Chicago",
"user_agent" : {
"product" : "curl",
"raw_value" : "curl/7.74.0",
"version" : "7.74.0"
},
"zip_code" : "37148"
}
$
Source
Comments
You can use a Mastodon accounti to comment on this article by replying to the associated Mastodon toot.