Last active
August 29, 2015 14:07
-
-
Save avin/c2599851d063c0767d5f to your computer and use it in GitHub Desktop.
Show current bandwith using tcpdump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Usage: tcpdump -i ng10 -l -e -n dst host 192.168.1.200 | ./tcpdump_bps.pl | |
use strict; | |
use warnings; | |
use Time::HiRes; | |
my $reporting_interval = 10.0; # seconds | |
my $bytes_this_interval = 0; | |
my $start_time = [Time::HiRes::gettimeofday()]; | |
while (<>) { | |
if (/ length (\d+):/) { | |
$bytes_this_interval += $1; | |
my $elapsed_seconds = Time::HiRes::tv_interval($start_time); | |
if ($elapsed_seconds > $reporting_interval) { | |
my $bps = $bytes_this_interval / $elapsed_seconds; | |
printf "%02d:%02d:%02d %10.2f Bps\n", (localtime())[2,1,0],$bps; | |
$start_time = [Time::HiRes::gettimeofday()]; | |
$bytes_this_interval = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment