in reply to Extracting data from a firewall log

Ok, I seem to be struggling here. I was wondering if someone can help me out with a few lines of my file, as far as regular expressions. I seem to be really stuck at this point.

Let me show what I am trying to pull out of the file:

03/13/03 16:44:56 kernel Temporarily blocking host 212.241.116.21

(This is where the inital block occurs, the firewall will then continue to block all attempts from this IP address.I would like to extract all entries in the firewall like this one.)

03/13/03 16:44:57 firewalld103 deny in eth0 48 tcp 20 117 212.241.11.21 209.126.xxx.xxx 4449 80 syn (LO-Proxied-HTTP)

(At this point, the firewall continues to block the attempt. I would like to extract all lines in the firewall that contain this as well...contains very useful information such as ports and packet sizes.)

With that in mind, can I ask for someone to help me build my script? I feel like I am butting my head against a wall. I know I have much to learn, but can learn a lot from seeing the script and breaking it down to see how it functions.

Thanks.

Tarballed

  • Comment on Re: Extracting data from a firewall log

Replies are listed 'Best First'.
Re: Re: Extracting data from a firewall log
by zengargoyle (Deacon) on Apr 10, 2003 at 01:12 UTC

    roughly...

    ... my %lookfor; # will look like this at the end # %lookfor = ( # 192.168.254.1 => { # first => '03/13/03 16:44:56', # last => '03/13/03 16:59:30', # count => 12, # bytes => 1234 # }, # 192.168.254.2 => { # .... # } # ); # while (<FWLOG>) { if (/(.*?) kernel Temporarily blocking host (.*)/) { $lookfor{$2}{first} = $1; } elsif (/(.*?) firewalld.*? deny in eth0 (\d+) (\w+) (\d+) (\d+) ([\d +\.]+) (\d+) (\d+) (\w+) (.*)/) { if (exists $lookfor{$6}) { $lookfor{$6}{count} += 1; $lookfor{$6}{last} = $1; $lookfor{$6}{bytes} += $7; # or whichever field is bytes # keep track of other info of interest } # else ignore the uninteresting deny lines } # else ingore lines we don't care about at all } printf "%15s %6s %18s %18s %s\n", qw/ ip count first last bytes /; foreach my $badguy (keys %lookfor) { printf "%15s %6d %18s %18s %d\n", $badguy, $lookfor{$badguy}{count}, $lookfor{$badguy}{first}, $lookfor{$badguy}{last}, $lookfor{$badguy}{bytes}; }