File: user-agents.pl

package info (click to toggle)
squid 2.6.5-6etch5
  • links: PTS
  • area: main
  • in suites: etch
  • size: 12,540 kB
  • ctags: 13,801
  • sloc: ansic: 105,278; sh: 6,083; makefile: 1,297; perl: 1,245; awk: 40
file content (47 lines) | stat: -rwxr-xr-x 930 bytes parent folder | download | duplicates (22)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
#
# John@MCC.ac.uk
# John@Pharmweb.NET

require "getopts.pl";
&Getopts('FML:');

open (ACCESS, "/opt/Squid/logs/useragent.0");

while (<ACCESS>) {
	($host, $timestamp, $agent) = 
	/^(\S+) \[(.+)\] \"(.+)\"\s/;
	if ($agent ne '-') {
		if ($opt_M) {
		 	$agent =~ tr/\// /;
			$agent =~ tr/\(/ /;
		}
		if ($opt_F) {
			next unless $seen{$agent}++;
		} else {
			@inline=split(/ /, $agent);
			next unless $seen{$inline[0]}++;
		}
	}
}

$total=0;
if (!$opt_L) {$opt_L=0}

print "Summary of User-Agent Strings\n(greater than $opt_L percent)\n\n";

foreach $browser (keys(%seen)) {
        $total=$total+$seen{$browser};
}

foreach $browser (sort keys(%seen)) {
	$percent=$seen{$browser}/$total*100;
	if ($percent >= $opt_L) { write; }
}

print "\n\nTotal entries in log = $total\n";

format STDOUT =
@>>>>>>> :@##.####% : @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$seen{$browser}, $percent, $browser
.