└── geoip.rb /geoip.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'hpricot' 3 | require 'open-uri' 4 | 5 | file = File.open('/Users/daniel/Development/newfile', 'w') 6 | 7 | File.open('/Users/daniel/Development/ips').each { |line| 8 | doc = Hpricot(open("http://ipinfodb.com/ip_query.php?ip=#{line}")) 9 | (doc/'response').each do|el| 10 | ip = (el/'ip').inner_html 11 | country = (el/'countryname').inner_html 12 | state = (el/'regionname').inner_html 13 | city = (el/'city').inner_html 14 | puts "#{ip},#{country},#{state},#{city}" 15 | file.puts "#{ip},#{country},#{state},#{city}" 16 | file.flush 17 | end 18 | } 19 | --------------------------------------------------------------------------------