55.unless response.is_a?(Net::HTTPSuccess) 56. abort "Request failed with status #{response.code}" 57.end 58. 59.omni = Hash[fields.zip(response.body.encode('utf-8', 'iso-8859-1').parse_csv)] 60. 61.if omni[:error] 62. abort "MaxMind returned an error code for the request: #{omni[:error]}" 63.else 64. puts 65. puts "MaxMind Omni data for #{options[:ip]}"; 66. puts 67. omni.each { |key, val| printf " %-20s %s\n", key, val } 68. puts 69.end #!/usr/bin/env ruby
require 'csv' require 'net/http' require 'open-uri' require 'optparse' require 'uri'
fields = [:country_code, :country_name, :region_code, :region_name, :city_name, :latitude, :longitude, :metro_code, :area_code, :time_zone, :continent_code, :postal_code, :isp_name, :organization_name, :domain, :as_number, :netspeed, :user_type, :accuracy_radius, :country_confidence, :city_confidence, :region_confidence, :postal_confidence, :error]
options = { :license => "YOUR_LICENSE_KEY", :ip => "24.24.24.24" } OptionParser.new { |opts| opts.banner = "Usage: omni-geoip-ws.rb [options]"
opts.on("-l", "--license LICENSE", "MaxMind license key") do |l| options[:license] = l end
opts.on("-i", "--ip IPADDRESS", "IP address to look up") do |i| options[:ip] = i end }.parse!
uri = URI::HTTP.build(:scheme => 'http', 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>
|