Today is: 26 January, 2012
Check todays hot topics

Hoodrich Network Statistics

lol old. Who needs iptraf or any other horse shit to tell you whats going through your NIC. We got perl function calls older than you are!

#! /usr/bin/perl
 
for $i (0 .. 15 ) {
  $rx[$i] = 0 ;
  $ox[$i] = 0 ;
} ;
 
format STDOUT_TOP =
                        Network Statistics
 Received (eth0)                           Transmitted (eht0)
     Bytes       Packets errors  drops     Bytes      Packets   errors
Drops  Colls
 
------------------------------------------------------------------------------------
.
 
format STDOUT =
 @>>>>>>>>>>>@>>>>>>>>>>>@>>>>>>@>>>>>>@>>>>>>>>>>>@>>>>>>>>>>>@>>>>>>@>>>>>>@>>>>>>
 $net[0]       $net[1]   $net[2] $net[3]$net[8]     $net[9]    $net[10]$net[11]$net[13]
.
 
while (1)
{
 $ex = `cat /proc/net/dev | grep eth0` ;
 chop ($ex ) ;
 $ex =~ s/   / /g;
 $ex =~ s/  / /g;
 $ex =~ s/  / /g;
 
 ( undef, $rx[0], $rx[1], $rx[2], $rx[3], $rx[4], $rx[5], $rx[6], $rx[7],
  $rx[8], $rx[9], $rx[10], $rx[11], $rx[12], $rx[13], $rx[14], $rx[15] )
  = split ( / / , $ex ) ;
 
  $rx[0] =~ s/^eth0:// ;
  for $i ( 0 .. 15 ) {
    $net[$i] = $rx[$i] - $ox[$i] ;
    $ox[$i] = $rx[$i] ;
  } ;
  write ;
  #print "\n" ;
  sleep(1) ;
} ;

Check out that sweet format() write() action!

# ./net.pl 
                        Network Statistics
 Received (eth0)                           Transmitted (eht0)
     Bytes       Packets errors  drops     Bytes      Packets   errors
Drops  Colls
 
------------------------------------------------------------------------------------
   1964346493   101813342      0      0  3492468870    93966124      0      0      0
          774           9      0      0         942           5      0      0      0
           70           1      0      0         198           1      0      0      0
           70           1      0      0         198           1      0      0      0
           70           1      0      0         198           1      0      0      0
           70           1      0      0         198           1      0      0      0
           70           1      0      0         198           1      0      0      0
           70           1      0      0         198           1      0      0      0