Craig Hammer wrote:
> 
> I am working on a script to read in a firewall logfile, pull out the IP
> addresses of denied packets, then give me a count per IP address, and
> perform a whois on each address.
> 
> This previously ran as a VERY SLOW shell script.  In bourne, I used sort and
> then uniq to get a count per IP address.  Is there something similar to uniq
> within perl?  (I already have it sorting correctly)


Something like this for example:

my %address;
open LOG, '/var/log/yourlogfile' or die "Cannot open 'yourlogfile': $!";
while ( <LOG> ) {
    if ( /denied/i and /([\d.]+)/ ) {  # get IP address
        $address{$1}++;  # count unique IP addresses
        }
    }

for ( sort keys %address ) {
    print "IP address: $_  Count: $address{$_}\n";
    }



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to