Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Geolocate a number of IP addresses via shell script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Geolocate a number of IP addresses via shell script
Authored by: jolohaga on Jan 13, '10 09:50:08AM

Nice idea. I wanted it to work without temp files, as a one liner, and with only default Mac OS X apps (curl instead of lynx). I also use Ruby to strip the HTML. The result is below. (I use the TCSH shell, but modifying for Bash should be trivial.) I made an alias of the command and pass it the IP addr argument as variable \!:1. In .tcshrc you would define it as:

alias ip_location 'curl "http://www.geoiptool.com/en/?IP=\!:1" | sed -n "/Host\ Name/,/Postal\ code/p" | ruby -
e "puts STDIN.read.gsub(/<\/?[^>]*>/,nil.to_s)"'

You can name it anything you want. I happen to name it ip_location.



[ Reply to This | # ]
Geolocate a number of IP addresses via shell script
Authored by: alblue on Jan 13, '10 10:59:14AM

textutil is installed on all macs, and can convert between html and text pretty easily.

[edit] From 10.4 onwards ;-) I think it uses the same parsing libraries that Apple uses to read .docx stuff, too.

                   fmt is one of:  txt, html, rtf, rtfd, doc, docx, wordml,
                                   odt, or webarchive

HISTORY
     The textutil command first appeared in Mac OS X 10.4.
Edited on Jan 13, '10 11:01:49AM by alblue


[ Reply to This | # ]