#!/usr/bin/perl # Author: Peter R. Wood, http://prwdot.org/ use strict; use Socket; my %ips = (); my $search_criteria = ""; while (<>) { my $entry = $_; if ( $entry =~ /$search_criteria/o ) { my @fields = split( /\s+/, $entry ); my $ip = inet_aton( $fields[0] ); my $hostname = gethostbyaddr( $ip, AF_INET ); $ips{ $fields[0] }{'hostname'} = $hostname if $hostname; my $agent1 = $fields[11]; $entry =~ /$agent1(.*)$/; $ips{ $fields[0] }{'hits'}++; $ips{ $fields[0] }{'agents'}{ $agent1 . $1 }++; } } foreach my $ip ( sort { $ips{$a}{'hits'} <=> $ips{$b}{'hits'} } keys(%ips) ) { print "IP: $ip\nHostname: $ips{$ip}{'hostname'}\nHits: $ips{$ip}{'hits'}\n"; foreach my $agent ( sort { $ips{$ip}{'agents'}{$a} <=> $ips{$ip}{'agents'}{$b} } keys( %{ $ips{$ip}{'agents'} } ) ) { print "Agent $agent: $ips{$ip}{'agents'}{$agent}\n"; } print "\n"; }