42. 43.GetOptions( 44. 'license:s' => \$license_key, 45. 'ip:s' => \$ip_address, 46.); 47. 48.my $uri = URI->new('http://geoip.maxmind.com/e'); 49.$uri->query_param( l => $license_key ); 50.$uri->query_param( i => $ip_address ); 51. 52.my $ua = LWP::UserAgent->new( timeout => 5 ); 53.my $response = $ua->get($uri); 54. 55.die 'Request failed with status ' . $response->code() 56. unless $response->is_success(); 57. 58.my $csv = Text::CSV_XS->new( { binary => 1 } ); 59.$csv->parse( decode( 'ISO-8859-1', $response->content() ) ); 60. 61.my %omni; 62.@omni{@fields} = $csv->fields(); 63. 64.binmode STDOUT, ':encoding(UTF-8)'; 65. 66.if ( defined $omni{error} && length $omni{error} ) { 67. die "MaxMind returned an error code for the request: $omni{error}\n"; 68.} 69.else { 70. print "\nMaxMind Omni data for $ip_address\n\n"; 71. for my $field (@fields) { 72. print sprintf( " %-20s %s\n", $field, $omni{$field} ); 73. } 74. print "\n"; 75.} #!/usr/bin/env perl
use strict; use warnings;
use Encode qw( decode ); use Getopt::Long; use LWP::UserAgent; use Text::CSV_XS; use URI; use URI::QueryParam;
my @fields = qw( 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 );
my $license_key = 'YOUR_LICENSE_KEY'; my $ip_address = '24.24.24.24';
GetOptions( 'license:s' => \$license_key, 'ip:s' => \$ip_address, );
my $uri = URI->new('http://geoip.maxmind.com/e'); $uri->query_param( l => $ 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>
|