Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

There's tload that plots load average.

There's iftop that network usage as bars.

How to do something like this:

# tcpdump -i eth0 --plot 'host 1.2.3.4'
13:45:03  |                        | 0 in 0 out
13:45:04  |O                       | 0 in 1MB out
13:45:05  |OOOI                    | 500 KB in 4MB out
13:45:06  |OIIII                   | 6MB in 1MB out
13:45:07  |                        | 0 in 0 out
13:45:08  |IIIIIIIIIIII            | 53M in 0 out
share|improve this question
add comment

1 Answer

Well, if you have perl and tcpdump installed it shouldn't be too hard to hack something up...
Following script will output something like:

# ./host_traffic google.com
   0k
  30k ****************
  26k **************
  24k *************
  26k **************
  43k **********************
  39k ********************
  24k *************
  15k ********
   0k

I'll leave the sent/received bytes display as an exercise.

host_traffic:

#!/usr/bin/perl

$interface = "eth0";
$interval = 1;
$target_host = $ARGV[0];
$bytes = 0;

sub print_stats
{
    $nstars = $bytes / 2000;   # diagram scale = 2k
    $stars = "";
    for ($i = 0; $i < $nstars; $i++)
    { $stars .= "*"; }
    printf("%4ik $stars\n", $bytes / 1000);

    $bytes = 0;
    alarm $interval;
}

$SIG{ALRM} = sub { print_stats(); };
alarm $interval;
$pcap_filter = "ip src or dst $target_host";
open(IN, "tcpdump -s 500 -l -n -i $interface '$pcap_filter' | ");

while (my $s = <IN>)
{   # parse tcpdump output
    if ($s =~ m|(.*) IP (.*)\.([^.]*) > (.*)\.([^.]*): Flags \[(.*)\],.*, length (.*)|)
    {
        my ($timestamp, $src, $sport, $dst, $dport, $flags, $len) = ($1, $2, $3, $4, $5, $6, $7);   
        $bytes += $len;
        next;
    }
    print $s;
}
share|improve this answer
    
OK, thanks. But I expected some developed seasoned solution that is installable from repositories and have various options. As of the script, at minimum it should also support UDP. –  Vi. Dec 7 '12 at 2:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.