Over a million developers have joined DZone.

IP Location On Google Maps

·
/*
Example of usage:
$ ./lip.rb snippets.dzone.com
. Hostname: snippets.dzone.com
. Country Code: US
. Country Name: United States
. Region: CA
. Region Name: California
. City: Los Angeles
. Postal Code: 90017
. Latitude: 34.0530
. Longitude: -118.2642
. ISP: CoreExpress
. Organization: CoreExpress
. Metro Code: 803
. Area Code: 213
. Google Maps URL: http://maps.google.com/maps?q=34.0530,+-118.2642&iwloc=A&hl=en
*/


#!/usr/bin/env ruby -w

if ARGV.empty?
  puts <<-T
Locate IP by haqu
usage: ./lip.rb ip|domain ...
  T
  exit
end

require 'net/http'
require 'uri'

uri = URI.parse('http://www.maxmind.com/app/locate_ip')
res = Net::HTTP.post_form(uri,
  { 'ips' => ARGV.join(' '),
    'type' => '', 'u' => '', 'p' => ''
  } )
fstr = res.body

fstr.gsub!("Edition Results<\/span>

","CHECKPOINT") fstr =~ /CHECKPOINT(.+?)<\/table>/m fields = $1.grep(/<(th|td)>/) fields.each do |f| f.strip! f.gsub!(/<[^>]+>/,"") end (0...13).each do |i| puts ". #{fields[i]}: #{fields[i+13]}" end maplink = "http://maps.google.com/maps?q=#{fields[20]},+#{fields[21]}&iwloc=A&hl=en" puts ". Google Maps URL: #{maplink}"

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}