This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

!bw Bandwidth command

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
Z
Zecca93
Voice
Posts: 13
Joined: Thu Apr 26, 2012 9:09 pm

!bw Bandwidth command

Post by Zecca93 »

Hey is there script or can anybody make script for Bandwidth like this

<me> !bw
<bot> Upstream: 4.25kB/s (Uploaded: 3185.23MB) Downstream: 4.07kB/s (Downloaded: 592.80MB)

Thanks.
User avatar
spithash
Master
Posts: 248
Joined: Thu Jul 12, 2007 9:21 am
Location: Libera
Contact:

Post by spithash »

Code: Select all

namespace eval bandwidth {
  variable api "/proc/net/dev"
  variable interface "eth0:LAN" ;# for windows win:<something> without the others..
  # %IFN% : example eth0 # %IFA% : example WAN # %INC% : Incomming traffic # %OUT% : Outgoing traffic
  variable template "\[\002%IFA%\002\]: Incoming: \(\002%INC%\002\) kb/s Outgoing: \(\002%OUT%\002\) kb/s."
  # 0: privmsg to channel # 1: privmsg to nick # 2: notice to nick
  variable msgtype "0"
  variable pubflag "-"
  variable bandwidth "!bw"
  variable version 0.2
  switch -regexp [string tolower $::tcl_platform(platform)] {
    "win" {
      variable switch 1
    }
    "unix" {
      variable switch 2
    }
    ".*" { 
      variable switch 0
    }
  }
  switch  -exact $msgtype {
    "0" { variable msg "PRIVMSG %CHAN%" }
    "1" { variable msg "PRIVMSG %NICK%" }
    "2" { variable msg "NOTICE %NICK%" }
  }
 proc f {value} { 
 	set test $value ; set unit 0
 	while {[set test [expr {$test / 1024}]] > 0} {
 		incr unit
 	}
 	return [format "%.2f %s" [expr {$value / pow(1024,$unit)}] [lindex [list B KB MB GB TB PB EB ZB YB] $unit]]
 }

  proc totals {n u h c t} {
variable interface
	set iface [lindex [split $interface ":"] 0]
	set network [lindex [split $interface ":"] 1]

#catch {exec cut \-d. \-f1 /proc/uptime} reply; set secs [expr $reply % 60]; set mins [expr $reply / 60 % 60]; set hours [expr $reply / 3600 % 24]; set days [expr $reply / 86400]

catch {set useless [exec uptime]} uptime
#set uptime "${days}d ${hours}h ${mins}m ${secs}s"
	if {![catch {set data [exec /sbin/ifconfig $iface]} error]} {
		foreach line [split $data "\n"] {
			if {[string match "*RX bytes*" $line]} {
			set rxb [lindex [split [lindex $line 1] ":"] 1]
			set txb [lindex [split [lindex $line 5] ":"] 1]
			putserv "PRIVMSG $c :\002\[\002$network\002\]\002: total of [f $rxb] incoming, total of [f $txb] outgoing in $uptime."
			}
		}
	}
}
  proc bandwidth_pub {nick host hand chan arg} {
	totals $nick $host $hand $chan $arg
    variable switch; variable template; variable interface; variable msg; variable api
    if {[string equal 0 $switch]} {
      putlog "Error unknown operating system."
    } elseif {[string equal "1" $switch]} {
      if {[regexp -nocase {^(win):([a-zA-Z0-9\-]{1,100})$} $interface -> ifn ifa]} {
        set s_inc 0; set s_out 0; set e_inc 0; set e_out 0
        foreach {x} [split [exec netstat -e] \n] {
          if {[string equal -nocase -length 4 byte $x]} {
            set s_inc [lindex $x 1]
            set s_out [lindex $x 2]
          }
        }
        after 500
        foreach {x} [split [exec netstat -e] \n] {
          if {[string equal -nocase -length 4 byte $x]} {
            set e_inc [lindex $x 1]
            set e_out [lindex $x 2]
          }
        }
        putserv "[string map [list %NICK% $nick %CHAN% $chan] $msg] :[string map [list %IFN% $ifn %IFA% $ifa %INC% [format %.2f [expr ($e_inc - $s_inc) / 512.0]] %OUT% [format %.2f [expr ($e_out - $s_out) / 512.0]]] $template]"
      } else {
      	putlog "Script misconfiguration, check your settings."
      }
    } elseif {[string equal "2" $switch]} {
      if {[file exists $api]} {
        if {[file readable $api]} {
          if {[regexp {win:} $interface]} {
            putlog "Script misconfiguration, check your settings."
          } else {
            if {[catch {open $api} rf]} {
              putlog "Error couldn't open $api for an unknown reason."
            } else {
          	  while {![eof $rf]} {
          	    gets $rf x
                foreach {ifn ifa} [split $interface \x3a\x2c] {
                  regexp "$ifn:\[\x20\t\]{0,100}(\[0-9\]{1,100})\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}(\[0-9\]{1,100})\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}" $x -> s_inc($ifn) s_out($ifn)
                }
              }
              close $rf
            }
            after 500
            if {[catch {open $api} rf]} {
              putlog "Error couldn't open $api for an unknown reason."
            } else {
          	  while {![eof $rf]} {
          	    gets $rf x
                foreach {ifn ifa} [split $interface \x3a\x2c] {
                  if {[regexp "$ifn:\[\x20\t\]{0,100}(\[0-9\]{1,100})\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}(\[0-9\]{1,100})\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}\[\x20\t\]{1,100}\[0-9\]{1,100}" $x -> e_inc($ifn) e_out($ifn)]} {
                    putserv "[string map [list %NICK% $nick %CHAN% $chan] $msg] :[string map [list %IFN% $ifn %IFA% $ifa %INC% [format %.2f [expr ($e_inc($ifn) - $s_inc($ifn)) / 512.0]] %OUT% [format %.2f [expr ($e_out($ifn) - $s_out($ifn)) / 512.0]]] $template]"
                  }
                }
              }
              close $rf
            }
          }
        } else { putlog "Error $api is not readable."  }
      } else { putlog "Error $api does not exist." }
    } else { putlog "Error unknown operating system." }
  }
  bind pub $pubflag $bandwidth [namespace current]::bandwidth_pub
}
Libera ##rtlsdr & ##re - Nick: spithash
Click here for troll.tcl
Post Reply