:host => 'geoip.maxmind.com', :path => '/e', :query => URI.encode_www_form(:l => options[:license], :i => options[:ip]))
response = Net::HTTP.get_response(uri)
unless response.is_a?(Net::HTTPSuccess) abort "Request failed with status #{response.code}" end
omni = Hash[fields.zip(response.body.encode('utf-8', 'iso-8859-1').parse_csv)]
if omni[:error] abort "MaxMind returned an error code for the request: #{omni[:error]}" else puts puts "MaxMind Omni data for #{options[:ip]}"; puts omni.each { |key, val| printf " %-20s %s\n", key, val } puts end 最后再来个Perl版本吧:
[python] view plaincopyprint? 01.#!/usr/bin/env perl 02. 03.use strict; 04.use warnings; 05. 06.use Encode qw( decode ); 07.use Getopt::Long; 08.use LWP::UserAgent; 09.use Text::CSV_XS; 10.use URI; 11.use URI::QueryParam; 12. 13.my @fields = qw( 14. country_code 15. country_name 16. region_code 17. region_name 18. city_name 19. latitude 20. longitude 21. metro_code 22. area_code 23. time_zone 24. continent_code 25. postal_code 26. isp_name 27. organization_name 28. domain 29. as_number 30. netspeed 31. user_type 32. accuracy_radius 33. country_confidence 34. city_confidence 35. region_confidence 36. postal_confidence 37. error 38.); 39. 40.my $license_key = 'YOUR_LICENSE_KEY'; 41.my $ip_address = '24.24.24.24';
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>
|