Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .