Current location: Hot Scripts Forums » Programming Languages » Perl » Count requesters from an apache log file

Count requesters from an apache log file

Reply
  #1 (permalink)  
Old 03-16-06, 09:55 PM
ddolddolee82 ddolddolee82 is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Count requesters from an apache log file

Given an apache log file(only a partial) below, I need to count top requesters by IP address.
Anybody have any idea about doing this?


Top 10 Requesters
-----------------
1: 130.85.25.98 (8839 requests)
2: 66.249.66.162 (7689 requests)
3: 151.200.214.162 (1481 requests)
4: 130.85.12.11 (1314 requests)
5: 141.156.232.113 (1126 requests)
6: 24.89.25.44 (932 requests)
7: 69.175.88.27 (916 requests)
8: 199.68.77.225 (848 requests)
9: 68.34.20.194 (830 requests)
10: 130.85.194.161 (793 requests)


130.85.25.99 - - [19/Feb/2006:00:16:13 -0500] "GET /oit/newmedia/uportal/blog/index.xml HTTP/1.1" 200 7636 "-" "Java/1.4.2_10"
68.142.250.104 - - [19/Feb/2006:00:16:13 -0500] "GET /Alumni/gallery/2000/Homecoming HTTP/1.0" 302 302 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"
141.156.13.14 - - [19/Feb/2006:00:16:13 -0500] "GET /reslife/apply/apply_rates.html HTTP/1.1" 200 17090 "http://www.umbc.edu/reslife/communities/ter.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
141.156.13.14 - - [19/Feb/2006:00:16:13 -0500] "GET /reslife/apply/apply_rates.html HTTP/1.1" 200 17090 "http://www.umbc.edu/reslife/communities/ter.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
68.88.67.57 - - [19/Feb/2006:00:16:13 -0500] "GET /se/images/UMBCNavigationBar(JOSH).jpg HTTP/1.1" 200 18578 "http://www.umbc.edu/se/computercd.htm" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
209.19.221.70 - - [19/Feb/2006:00:16:13 -0500] "GET /financialaid HTTP/1.1" 301 318 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"
141.156.13.14 - - [19/Feb/2006:00:16:13 -0500] "GET /reslife/apply/apply_rates.html HTTP/1.1" 200 17090 "http://www.umbc.edu/reslife/communities/ter.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
130.85.25.99 - - [19/Feb/2006:00:16:13 -0500] "GET /oit/newmedia/uportal/blog/index.xml HTTP/1.1" 200 7636 "-" "Java/1.4.2_10"
130.85.25.99 - - [19/Feb/2006:00:16:13 -0500] "GET /oit/newmedia/uportal/blog/index.xml HTTP/1.1" 200 7636 "-" "Java/1.4.2_10"
68.142.250.148 - - [19/Feb/2006:00:16:13 -0500] "GET /doc/cmlib/doc/eispack/comlr.html HTTP/1.0" 200 2667 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"
172.146.105.105 - - [19/Feb/2006:00:16:13 -0500] "GET /newsevents/insights/archives/2005/11/q_a_with_devin.html HTTP/1.1" 200 17877 "http://www.umbc.edu/insights/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"
141.156.13.14 - - [19/Feb/2006:00:16:14 -0500] "GET /reslife/apply/images/subheadings/subheadings_room.gif HTTP/1.1" 200 1613 "http://www.umbc.edu/reslife/apply/apply_rates.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
141.156.13.14 - - [19/Feb/2006:00:16:14 -0500] "GET /reslife/apply/images/headings/headings_apply_rates.gif HTTP/1.1" 200 46389 "http://www.umbc.edu/reslife/apply/apply_rates.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
141.156.13.14 - - [19/Feb/2006:00:16:14 -0500] "GET /reslife/apply/images/subheadings/subheadings_board.gif HTTP/1.1" 200 1777 "http://www.umbc.edu/reslife/apply/apply_rates.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
209.19.221.70 - - [19/Feb/2006:00:16:14 -0500] "GET /financialaid/ HTTP/1.1" 200 8507 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"
71.248.5.110 - - [19/Feb/2006:00:16:14 -0500] "GET /undergrad/p_check1.html HTTP/1.1" 200 10745 "http://www.umbc.edu/undergrad/parents.html" "Mozilla/4.0 (compatible; MSIE 5.16; Mac_PowerPC)"
141.156.13.14 - - [19/Feb/2006:00:16:14 -0500] "GET /reslife/apply/images/subheadings/subheadings_fee2.gif HTTP/1.1" 200 5256 "http://www.umbc.edu/reslife/apply/apply_rates.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
141.156.13.14 - - [19/Feb/2006:00:16:14 -0500] "GET /reslife/images/sidebars/sidebar_index_prospectiv-02.gif HTTP/1.1" 404 330 "http://www.umbc.edu/reslife/apply/apply_rates.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
141.156.13.14 - - [19/Feb/2006:00:16:14 -0500] "GET /reslife/images/sidebars/sidebar_index_apply_ret_01-.gif HTTP/1.1" 404 330 "http://www.umbc.edu/reslife/apply/apply_rates.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
141.156.13.14 - - [19/Feb/2006:00:16:14 -0500] "GET /reslife/apply/images/apply_sidebar_fresh_01-over.gif HTTP/1.1" 404 327 "http://www.umbc.edu/reslife/apply/apply_rates.html" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-17-06, 03:08 AM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
one way:

Code:
use strict;
my %top_ten = ();
open(LOG,'<log.txt') or die "can't open log.txt: $!";
while(my $line = <LOG>){
   my ($ip) = $line =~ /^([^\s]+)/;
   $top_ten{$ip}++;
}
close(LOG);
my @top_list = map {"$_->[0] ($_->[1] requests)"}
               sort {$b->[1] <=> $a->[1]}
               map {[$_,$top_ten{$_}]} keys %top_ten;

for my $i (0..9) {
   print "@{[$i+1]}: $top_list[$i]\n";
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form to Text File Justin171985 PHP 12 09-22-09 05:36 PM
Error message not getting displayed. sanjeet Windows .NET Programming 0 12-20-05 10:48 AM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
how to convert log file to xml perlguru Perl 1 01-28-05 12:12 AM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM


All times are GMT -5. The time now is 07:14 AM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.