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}; }

In reply to Re: Re: Extracting data from a firewall log by zengargoyle
in thread Extracting data from a firewall log by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.