Sean’s Obsessions

Sean Walberg’s blog

Command Line Geolocation

A comment in a Slashdot article lead me to iploc.org, specifically Country names zone which lets you get the country for a given IP address over DNS.

I wrapped it in a bash function… throw this at the end of your .bashrc:

1
2
geo() { dig +short TXT `echo $1 | \
 awk -F. '{print $4"."$3"."$2"."$1".cc.iploc.org"}'`;}

and you can get geo information from the command line:

1
2
$ geo 204.187.154.1
"CA"

Comments

I’m trying something new here. Talk to me on Twitter with the button above, please.