#!/usr/local/bin/perl # # Find "connect from" lines in a supplied syslog, and build stats # for network connections accepted and refused for each network # service. # #$debug = 1; while (<>) { chop; # @a = split(/[][ :]+/); if (/ ([A-Za-z0-9.]+)\[[0-9]+\]: refused connect from (.*)$/) { $a = $1 . ':' . $2; $refused{$a}++; print "Found refused: $_\n" if $debug; print "key is $a\n" if $debug; } elsif (/ ([A-Za-z0-9.]+)\[[0-9]+\]: connect from (.*)$/) { $a = $1 . ':' . $2; $connects{$a}++; print "Found connect: $_\n" if $debug; print "key is $a\n" if $debug; } } print "Accepted connections:\n"; @accepted_keys = keys(connects); foreach $key (sort @accepted_keys) { printf "%-40s %4d\n", $key, $connects{$key}; } print "\nRefused connections:\n"; @refused_keys = keys(refused); foreach $key (sort @refused_keys) { printf "%-40s %4d\n", $key, $refused{$key}; }