Sean’s Obsessions


  • I'm a happy Linode customer. This is a Linode 540 VPS. Linode periodically increases RAM and disk while keeping costs steady, which makes them the natural choice.
  • Archives

25 Jan

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:

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:

$ geo 204.187.154.1
"CA"

2 Responses to “Command line geolocation”

  1. 1
    Sean Cody Says:

    A bit of a bug.

    The braces are unbalanced.

    Here’s what works from my .bash_login:


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

  2. 2
    sean Says:

    You’re right, my template cut off the last few characters.

Leave a Reply

© 2010 Sean’s Obsessions | Entries (RSS) and Comments (RSS)

Powered by Wordpress, design by Web4Sudoku, based on Pinkline byGPS Gazette