<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: location code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 21 Aug 2008 14:00:58 GMT</pubDate>
    <description>DZone Snippets: location code</description>
    <item>
      <title>IP Location on Google Maps</title>
      <link>http://snippets.dzone.com/posts/show/3814</link>
      <description>/*&lt;br /&gt;Example of usage:&lt;br /&gt;$ ./lip.rb snippets.dzone.com&lt;br /&gt;. Hostname: snippets.dzone.com&lt;br /&gt;. Country Code: US&lt;br /&gt;. Country Name: United States&lt;br /&gt;. Region: CA&lt;br /&gt;. Region Name: California&lt;br /&gt;. City: Los Angeles&lt;br /&gt;. Postal Code: 90017&lt;br /&gt;. Latitude: 34.0530&lt;br /&gt;. Longitude: -118.2642&lt;br /&gt;. ISP: CoreExpress&lt;br /&gt;. Organization: CoreExpress&lt;br /&gt;. Metro Code: 803&lt;br /&gt;. Area Code: 213&lt;br /&gt;. Google Maps URL: http://maps.google.com/maps?q=34.0530,+-118.2642&amp;iwloc=A&amp;hl=en&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby -w&lt;br /&gt;&lt;br /&gt;if ARGV.empty?&lt;br /&gt;  puts &lt;&lt;-T&lt;br /&gt;Locate IP by haqu&lt;br /&gt;usage: ./lip.rb ip|domain ...&lt;br /&gt;  T&lt;br /&gt;  exit&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;require 'uri'&lt;br /&gt;&lt;br /&gt;uri = URI.parse('http://www.maxmind.com/app/locate_ip')&lt;br /&gt;res = Net::HTTP.post_form(uri,&lt;br /&gt;  { 'ips' =&gt; ARGV.join(' '),&lt;br /&gt;    'type' =&gt; '', 'u' =&gt; '', 'p' =&gt; ''&lt;br /&gt;  } )&lt;br /&gt;fstr = res.body&lt;br /&gt;&lt;br /&gt;fstr.gsub!("Edition Results&lt;\/span&gt;&lt;p&gt;","CHECKPOINT")&lt;br /&gt;fstr =~ /CHECKPOINT(.+?)&lt;\/table&gt;/m&lt;br /&gt;fields = $1.grep(/&lt;(th|td)&gt;/)&lt;br /&gt;fields.each do |f|&lt;br /&gt;  f.strip!&lt;br /&gt;  f.gsub!(/&lt;[^&gt;]+&gt;/,"")&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;(0...13).each do |i|&lt;br /&gt;  puts ". #{fields[i]}: #{fields[i+13]}"&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;maplink = "http://maps.google.com/maps?q=#{fields[20]},+#{fields[21]}&amp;iwloc=A&amp;hl=en"&lt;br /&gt;puts ". Google Maps URL: #{maplink}"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 14 Apr 2007 13:33:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3814</guid>
      <author>haqu (Sergey)</author>
    </item>
  </channel>
</rss>
