文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>简单统计Apache日志IP的perl脚本

简单统计Apache日志IP的perl脚本

时间:2007-01-11  来源:hello386

Apache日志的格式如下: 192.168.1.48 - - [01/Dec/2006:00:00:38 +0800] "GET /xxt/ui/index.html HTTP/1.1" 304 -
192.168.1.48 - - [01/Dec/2006:00:00:38 +0800] "GET /xxt/ui/yp_index.html HTTP/1.1" 304 -
192.168.1.48 - - [01/Dec/2006:00:00:38 +0800] "GET /xxt/ui/js/TopUtilNoAction.js HTTP/1.1" 304 -
192.168.1.48 - - [01/Dec/2006:00:00:38 +0800] "GET /xxt/ui/yp_header.html HTTP/1.1" 304 -
192.168.1.48 - - [01/Dec/2006:00:00:38 +0800] "GET /xxt/ui/yp_main.html HTTP/1.1" 304 -
192.168.1.48 - - [01/Dec/2006:00:00:38 +0800] "GET /xxt/ui/yp_bottom.jsp HTTP/1.1" 200 2446
192.168.1.48 - - [01/Dec/2006:00:00:39 +0800] "GET /xxt/ui/yp_right.html HTTP/1.1" 304 -
192.168.1.48 - - [01/Dec/2006:00:00:39 +0800] "GET /xxt/ui/global.html HTTP/1.1" 304 -
192.168.1.48 - - [01/Dec/2006:00:00:39 +0800] "GET /xxt/ui/touchPen.html HTTP/1.1" 304 -
192.168.1.48 - - [01/Dec/2006:00:00:38 +0800] "GET /xxt/ui/yp_scroll_news.jsp HTTP/1.1" 200 2509
  ........   程序如下:       #--------------------------Begin--------------------------------------------  
$log_name="E:/work/weblizer/logs/2006_12_01access_log"; #要分析的日志文件
  open (file_log,$log_name) || die ("open log file failed");   print (" .... $log_name......\n");   %ip_count=();#定义了个关联数组,记录日志中出现IP的次数
$totle=0;
$i = 1;
while ($line_log = <file_log>) #从log文件中读入一行
{

 @log_ip = split(/\s+/,$line_log); #按空字符分割
 
 $ip_count{$log_ip[0]}+=1;#对应的IP计数加一
 
}

close (file_log);
  print("capitalized ip and number of occurrences: \n");   foreach $cap_ip (keys(%ip_count)) {
    print("$cap_ip <<==>>  $ip_count{$cap_ip} \n");
    $totle += $ip_count{$cap_ip};
 
}

print "\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n";
print   "x totle hit of ip: >>>>  $totle x";
print "\nxxxxxxxnxxxxxxxxxxxxxxxxxxxxxxxxx\n";
      #-------------------The End----------------------------
相关阅读 更多 +
排行榜 更多 +
我要当超人

我要当超人

休闲益智 下载
幸存者的命运

幸存者的命运

飞行射击 下载
精英战区3d

精英战区3d

飞行射击 下载