1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
my @logentries = <FH>;
foreach (@logentries) {
next unless ($_ !~ /^\s*$/);
$_ =~ m/(\d+.\d+.\d+.\d+)\s-\s-\s\[(\d{2}\/\w+\/\d{4}\:\d{2}\:\d{2}\:\d{2})\s\+0000\]\s\"\w+\s\S+\s\S+\s\S+\s\S+\s\S+\s\"(.+?)\(/;
$ip = $1;
push (@ipadressen, $ip);
$date = $2;
push (@timeresult, $date);
$starttime = $timeresult[0];
$endtime = $timeresult[$#timeresult];
$useragent = $3;
push (@agent, $useragent);
$line++;
}
close FH;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $file='logs.txt'; my @ips; my @agents; my @timeresult; open(my $fh, '<', $file) or die("error open $file ($!)\n"); while(my $line=<$fh>) { if($line=~/([\d.]+) - - \[(.+?)\] "(.+?)" (\d+) (\d+) "(.+?)" "(.+?)"/) { my ($ip,$time,$request,$result,$filesize,$referer,$useragent)=($1,$2,$3,$4,$5,$6,$7); push(@timeresult,$time); push(@ips,$ip); push(@agents,$useragent); } } close($fh); my $starttime=$timeresult[0]; my $endtime=$timeresult[-1]; print Dumper(\@ips); print Dumper(\@agents);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $file='logs.txt'; my @data; open(my $fh, '<', $file) or die("error open $file ($!)\n"); while(my $line=<$fh>) { if($line=~/([\d.]+) - - \[(.+?)\] "(.+?)" (\d+) (\d+) "(.+?)" "(.+?)"/) { push(@data,{ ip => $1, time => $2, request => $3, result => $4, filesize => $5, referer => $6, useragent=> $7, }); } } close($fh); my $starttime=$data[0]->{time}; my $endtime=$data[-1]->{time}; print Dumper(\@data);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# IP-Adressen: my %unique_ips; $unique_ips{$_->{ip}}++ for(@data); print Dumper(\%unique_ips); # Art der Zugriffe my %accesstypes; for my $entry (@data) { $accesstypes{$1}++ if($entry->{request}=~/^(\w+)\s/); } print Dumper(\%accesstypes); # Zugriffe pro Datei: my %files; for my $entry (@data) { my $req=$entry->{request}; if($req=~/^\w+\s+(.+$)\s+HTTP.+?$/) { $files{$1}++ } } print Dumper(\%files);