I'm trying to count unique ips based on a html log file and print that data to a webpage. i have the log file parsed but i am having trouble figuring out how to only select unique ip addresses to print to the webpage, any advice?
#!/usr/bin/perl use strict; use warnings; use 5.010; use POSIX; my $yesterday = strftime("%d/%b/%Y",localtime(time()-86400)); open(LOGFILE,"<", "access.log")or die"Could not open log file."; my $yesterdayHits=0; my $IPcount=0; my $totalhits=0; my $webPage='log.html'; my $startDate; open(WEBPAGE,">",$webPage); print WEBPAGE ("<HEAD><TITLE>Access Counts</TITLE></HEAD>"); print WEBPAGE ("<BODY>"); print WEBPAGE ("<H1> Today is: ",scalar(localtime), "</H1>"); print WEBPAGE ("<h3>Yesterday was $yesterday</h3>"); print WEBPAGE ("<h3>There are $IPcount unique vistors in the log</h3>" +); print WEBPAGE ("<TABLE BORDER=1 CELLPADDING=10 width='500px'>"); print WEBPAGE ("<Tr><td>IP</td><TD>LOGFILE</TD></Tr>\n\n"); foreach my $line (<LOGFILE>) { my %ips=(); $totalhits++; my $w = "(.+?)"; $line =~ m/^$w $w $w \[$w:$w $w\] "$w $w $w" $w $w$/; my @sort=$line; my $site = $1; my $logName = $2; my $fullName = $3; my $date = $4; my $time = $5; my $gmt = $6; my $req = $7; my $file = $8; my $proto = $9; my $status = $10; my $length = $11; $ips{$site} = $line; #print %ips; #foreach my $key ( sort keys %ips ) { # print $key, " => ", $ips{$key}, "\n"; #} my ($day,$month,$year)=split"\/",$date; my %dates = ( 'Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12', ); print WEBPAGE ("<Tr><td>$site</td><TD>$line</TD></Tr>\n\n") } close(LOGFILE); #print WEBPAGE ("<h2>Start Date is $startDate</h2>"); print WEBPAGE ("<h2>Total hits: $totalhits</h2>"); print WEBPAGE ("<h3>Hits Yesterday: $yesterdayHits</h3>"); print WEBPAGE ("</TABLE></P>"); print WEBPAGE ("</BODY></HTML>"); close(WEBPAGE);
In reply to unique visitors from html logfile by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |