Subject: scanlog.pl

From: "David C. Harris" <[email-masked]>
Date: Thu, 27 Jan 2005 00:48:17 -0800

#!/usr/bin/perl

# Testing

#print "Howdy doody, world\n";
#open(INFO, "< datafile" ) || die("can't open datafile: $!");

$linenum = 0;
while (<>) {
	@fields = split / /, $_;
	$linenum++;

	# Count IP's in day's log (assumes sorted):
	if ($linenum == 1) {
		$oldip = @fields[0];
		$ipcntr = 1;
	} elsif (@fields[0] == $oldip)  {
		# Another occurence of same IP:
		$oldip = @fields[0];
		$ipcntr++;
	} elsif (@fields[0] != $oldip) {
		# New IP value!
		printf "IP: %s, %s times\n", $oldip, $ipcntr;
		$oldip = @fields[0];
		$ipcntr = 1;
	} else {
		printf "IP: %s, %s times\n", $oldip, @fields[0];
	}
}
printf "IP: %s, %s times\n", $oldip, $ipcntr;