IP Location on Google Maps

December 6th, 2006

IP address or hostname on the input, detailed info and location on Google Maps on the output. Example of usage:

[~] lip nasa.gov
. Hostname: nasa.gov
. Country Code: US
. Country Name: United States
. Region: AL
. Region Name: Alabama
. City: Huntsville
. Postal Code: 35812
. Latitude: 34.6325
. Longitude: -86.6527
. ISP: National Aeronautics and Space Association
. Organization: National Aeronautics and Space Association
. Metro Code: 691
. Area Code: 256
. Google Map: http://maps.google.com/maps?q=34.6325,+-86.6527&iwloc=A&hl=en open? y

Last line is a generated link to Google Maps location. Press y and it will be opened in your browser.

nasa.gov on Google Maps

Here is a code on Ruby:

    1 #!/usr/bin/env ruby -w
    2 
    3 if ARGV.empty?
    4   puts <<-T
    5 ip address locator by dairon
    6 usage: lip <ip>...
    7   T
    8   exit
    9 end
   10 
   11 require 'net/http'
   12 require 'uri'
   13 
   14 res = Net::HTTP.post_form(URI.parse('http://www.maxmind.com/app/locate_ip'),
   15   { 'ips' => ARGV.join(' '),
   16     'type' => '',
   17     'u' => '',
   18     'p' => ''
   19   } )
   20 
   21 fstr = res.body
   22 # fstr = File.open('test.html','r').read
   23 
   24 fstr.gsub!("Edition Results<\/span><p>","CHECKPOINT1")
   25 fstr =~ /CHECKPOINT1(.+?)<\/table>/m
   26 fields = $1.grep(/<(th|td)>/)
   27 fields.each do |f|
   28   f.strip!
   29   f.gsub!(/<[^>]+>/,"")
   30 end
   31 
   32 (0...13).each do |i|
   33   puts ". #{fields[i]}: #{fields[i+13]}"
   34 end
   35 
   36 maplink = "http://maps.google.com/maps?q=#{fields[20]},+#{fields[21]}&iwloc=A&hl=en"
   37 print ". Google Map: #{maplink} open? "
   38 `o #{maplink}` if STDIN.getc == 121
   39 puts

1 Response Follows

  1. roger says

    nice