ga-infounused: Use `--no-textconv` in `git diff`
[sunny256-utils.git] / access_log_ip
blobb07f530057e4cad0b30a363f3ed54dc0a0b6cb41
1 #!/usr/bin/env perl
3 #=========================================================
4 # access_log_ip
5 # File ID: b6640aac-5d36-11df-9643-90e6ba3022ac
6 # Lister ut unike IP'er i access_log
7 #=========================================================
9 use strict;
10 use warnings;
11 use Socket;
13 $| = 1;
15 my %user_ip;
16 my $total_hits = 0;
17 my $no_lookup = 0;
19 defined($ARGV[0]) && ($ARGV[0] eq "-n") && (shift, $no_lookup = 1);
21 while (<>) {
22 if (m!^(\S+)\s+!) {
23 $user_ip{$1}++;
24 $total_hits++;
25 } else {
26 warn("Linje $.: Ulovlig format: \"$_\"");
30 my @ip_array = ();
32 while (my ($us_ip, $us_count) = each %user_ip) {
33 push(@ip_array, sprintf("%8u %15s (%6.2f%%) %s", $us_count, $us_ip, ($us_count/$total_hits)*100, ipname($us_ip)));
36 @ip_array = reverse sort @ip_array;
38 foreach(@ip_array) {
39 print("$_\n");
42 if (scalar(@ip_array) == 1) {
43 printf("\nTotalt 1 unik IP og 1 treff.\n");
44 } else {
45 printf("\nTotalt %u unike IP'er og $total_hits treff.\n", scalar(@ip_array));
48 sub ipname {
49 return("") if ($no_lookup);
50 my $i_addr = inet_aton(shift);
51 my $Retval = gethostbyaddr($i_addr, AF_INET);
52 defined($Retval) || ($Retval = "");
53 return $Retval;
54 } # ipname()
56 # 193.214.57.46 - - [18/Oct/2001:08:26:44 +0200] "POST / HTTP/1.0" 200 5147 "http://www.ba.no/00/07/12/9.html" "Mozilla/4.03 [en] (WinNT; I)"
57 # 62.113.158.67 - - [18/Oct/2001:08:26:44 +0200] "POST / HTTP/1.1" 200 15519 "http://basnakk.ba.no/" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)"
58 # 62.113.158.67 - - [18/Oct/2001:08:26:45 +0200] "GET / HTTP/1.1" 200 5137 "-" "Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt; SenseWave 1.0; IEwebPlus)"
59 # 193.213.227.243 - - [18/Oct/2001:08:26:45 +0200] "GET / HTTP/1.0" 200 14602 "http://www.ba.no/30/96/38/9.html" "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)"
60 # 193.217.216.52 - - [18/Oct/2001:08:26:45 +0200] "POST /tabell.php HTTP/1.1" 200 24122 "http://www.nifs.no/tabell.php" "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"
61 # 193.213.227.243 - - [18/Oct/2001:08:26:45 +0200] "GET /images/forside/laptop.jpg HTTP/1.0" 200 5347 "-" "Mozilla/3.01 (compatible;)"
62 # 62.113.158.67 - - [18/Oct/2001:08:26:46 +0200] "POST / HTTP/1.1" 200 15461 "http://basnakk.ba.no/" "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt; SenseWave 1.0)"
63 # 62.113.158.68 - - [18/Oct/2001:08:26:46 +0200] "POST / HTTP/1.1" 200 17032 "http://basnakk.ba.no/" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
64 # 62.113.158.67 - - [18/Oct/2001:08:26:46 +0200] "GET / HTTP/1.1" 200 5144 "-" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)"
65 # 62.113.158.68 - - [18/Oct/2001:08:26:49 +0200] "POST / HTTP/1.1" 200 16747 "http://basnakk.ba.no/" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
67 #### End of file access_log_ip ####