Top

Bandwidth traffictool


TCL Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  6.5 (of 2 scores)
Date Added  Nov 16, 2008
Last Updated  Nov 16, 2008
Tags  bandwidth  linux  traffic 

Introduction

This is a simple traffictool which shows incoming and outgoing data and packets.
Introduction:

Save the file to yourfile.tcl

Start it by using tclsh yourfile.tcl

Note: this script is linux only.

Grab the Code

proc getfirst {} {
        foreach i [split [exec cat /proc/net/dev] \n] {
                if {[string match -nocase *eth0:* "$i"]} {
                        set firstin [lindex [split [lindex $i 0] :] 1]
                        set firstout [lindex $i 8]
                        set fpackin [lindex $i 1]
                        set fpackout [lindex $i 9]
                        after 1000 [list getsecond $firstin $firstout $fpackin $fpackout]
                }
        }
}
proc len {data} {
        if {$data>=1000000} {
                return [expr {$data/1000000}]mbit/s
        } elseif {$data>=1000} {
                return [expr {$data/1000}]kbit/s
        } else {
                return $datab/s
        }
}
proc getsecond {firstin firstout fpackin fpackout} {
        set a $firstin
        set b $firstout
        set c $fpackin
        set d $fpackout
        foreach i [split [exec cat /proc/net/dev] \n] {
                if {[string match -nocase *eth0:* "$i"]} {
                        set secondin [lindex [split [lindex $i 0] :] 1]
                        set secondout [lindex $i 8]
                        set spackin [lindex $i 1]
                        set spackout [lindex $i 9]
                        exec clear >@ stdout
                        puts "Bandwidth: In: [len [expr {$secondin-$a}]] | Out: [len [expr {$secondout-$b}]]"
                        puts "Packets: In: [expr {$spackin-$c}]packets/s | Out: [expr {$spackout-$d}]packets/s"
                        getfirst
                }
        }
}
exec clear >@ stdout
puts "Traffictool by shitbreak is starting."
after 2000 [list exec clear >@ stdout]
after 2000 getfirst
vwait forever

Comments

  (1)  RSS
Noutrious
Comments: 365
 
TCL Snippet:  Bandwidth traffictool
Posted on Nov 17, 2008 2:29 am
Nice.

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom