根据域名获取Google Maps URL

  if ARGV.empty?
    puts <<-T
usage: ruby example.rb www.iteye.com
    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><p>", "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}"

 

输入ruby example.rb www.google.com

 

示例输出:

 

. Hostname: www.google.com
. Country Code: US
. Country Name: United States
. Region: CA
. Region Name: California
. City: Mountain View
. Postal Code: 94043
. Latitude: 37.4192
. Longitude: -122.0574
. ISP: Google
. Organization: Google
. Metro Code: 807
. Area Code: 650
. Google Maps URL: http://maps.google.com/maps?q=37.4192,+-122.0574&iwloc=A&hl=en

 

你可能感兴趣的:(.net,Google,F#,Ruby)