#!/usr/local/bin/perl
use LWP::Simple qw(get);
use Encode;
use Encode::CN;
use JSON;
use URI::Escape;
open (LOG ,"<","129_2");
while (<LOG>){
$ip = $_;
print "hostip is $_\n";
$host = "http://ip.taobao.com/service/getIpInfo.php?ip=$_";
$content = get($host);
$content =~ s/\\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;
$content=encode(gbk,$content);
if ($content =~ /(.*?)"region":(.*?),"region_id"(.*?)"city":(.*?),(.*?)/){
$a = $2;
$b = $4;
$a =~ s/"//g ;
$b =~ s/"//g ;
if ($b ){$city = $b;}else{
$city = $a;};
$city =~ s/"//g ;
print "\$city is $city\n";
}
open (B ,">>x.log");
print B ("$city $ip\n");
print "$content\n"};
open (LOG ,"<","x.log");
while (<LOG>) {
chomp;
$var= (split / /, $_)[0];
$log{$var}++;
}
while(my($city, $times) = each %log) {
print "$city $times\n";
open (C ,">>y.log");
print B ("$city $times\n");
}