added keepalive tool
[tridge/junkcode.git] / iptraflog.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my $totals;
6 my $t_in;
7 my $t_out;
8
9 while (my $line = <>) {
10         chop $line;
11         if ($line =~ /^(\w+\/\d+):.*?(\d+) bytes incoming.*?(\d+) bytes outgoing/) {
12                 $totals->{$1}->{'in'} = $2;
13                 $totals->{$1}->{'out'} = $3;
14         }
15 }
16
17 foreach my $protocol (sort keys %$totals) {
18         my $p_in = $totals->{$protocol}->{in} / 1.0e6;
19         my $p_out = $totals->{$protocol}->{out} / 1.0e6;
20         $t_in += $totals->{$protocol}->{in};
21         $t_out += $totals->{$protocol}->{out};
22         print "$protocol  $p_in $p_out\n";
23 }
24
25 printf "Total in %.1f MB   Total out %.1f MB\n", $t_in/1.0e6, $t_out/1.0e6;
26