Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl use strict; use warnings; my $logfile = $ARGV[0]; my $start_date; my $end_date; my %log_totals; open (FILE< $logfile) or die "Could not open $logfile: $!\n"; for (<FILE>) { if (/^\d+/) { ($start_date) = m/^(\d+)/o unless ($start_date); ($end_date) = m/^(\d+)/o; } elsif (/^\s+\d+/o) { my ($bytes,$source,$destination,$ports) = m/ ^\s+\d+\s+(\d+) # pkts & bytes .+ # bla bla bla \s+(\S+) # source \s+(\S+) # destination \s+(n\/a|\w+\s+->\s+\w+)$ # ports /ox; my ($src_port,$dest_port) = ('any','any'); ($src_port,$dest_port) = $ports =~ m/(\w+)\s+->\s+(\w+ +)/o unless ($ports eq 'n/a'); &data2hash($bytes,$source,$src_port,$destination,$dest +_port); # print "$bytes,$source,$src_port,$destination,$dest_p +ort\n"; } } my $start = localtime($start_date); my $end = localtime($end_date); print "From: $start\n"; print "To: $end\n"; print "Source Address,Source Port,Destination Address,Destination Port +,Bytes\n"; for my $key (keys %log_totals) { print "$key,$log_totals{$key}\n"; } sub data2hash { my ($bytes,$src_addr,$src_port,$dest_addr,$dest_port) = @_; if ($src_addr ne 'anywhere') { # we have a src address match if ($src_port ne 'any') { # we have a src port match $log_totals{"$src_addr,$src_port,,"} += $bytes +; } elsif ($dest_port ne 'any') { # we have a dest port +match $log_totals{"$src_addr,,,$dest_port"} += $byte +s; } else { # only src address match $log_totals{"$src_addr,,,"} += $bytes; } } elsif ($dest_addr ne 'anywhere') { # we have a dest address +match if ($src_port ne 'any') { # we have a src port match $log_totals{",$src_port,$dest_addr,"} += $byte +s; } elsif ($dest_port ne 'any') { # we have a dest port +match $log_totals{",,$dest_addr,$dest_port"} += $byt +es; } else { # only dest address match $log_totals{",,$dest_addr,"} += $bytes; } } else { # shouldn't get here print STDERR "eh?\n"; } } close FILE; #!/bin/bash /bin/date +%s >>/var/log/ip-acc/ip-acc.log /sbin/ipchains -L ip-acc -v -x >>/var/log/ip-acc/ip-acc.log /sbin/ipchains -Z ip-acc

In reply to IP Accounting parser by Viking

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (4)
    As of 2018-05-20 20:15 GMT
    Find Nodes?
      Voting Booth?