Guest User

tcl para router zyxel

a guest
May 18th, 2018
365
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #http://192.168.1.254:9999/SysStatistics_ADSL.html
  2. bind pub -|- "!statszyxel" zyxel
  3.  
  4. proc zyxel {nick host handle chan text} {
  5. set validargs [list "" -help -S -s -W -w -L -l -noise -noiset]
  6. set validargfound 0
  7. foreach i $validargs {
  8.   if {$i==$text} {set validargfound 1}
  9. }
  10. if {$validargfound==0} {
  11.   putquick "privmsg $chan :Invalid argument \002$text\002. Try -help for help."
  12.   return
  13. }
  14. if {$text=="-help"} {
  15. putquick "privmsg $chan :ZyXEL script for eggdrop. Usage:"
  16. putquick "privmsg $chan : -s       Displays System Monitor status only"
  17. putquick "privmsg $chan : -w       Displays WAN Port Statistics status only"
  18. putquick "privmsg $chan : -n       Displays LAN Port Statistics status only"
  19. putquick "privmsg $chan : <empty>  Displays all the 3 items above together"
  20. putquick "privmsg $chan : -noise   Displays DSL Line Status only"
  21. putquick "privmsg $chan : -noiset  Displays DSL Line Status table-like only"
  22. return 0
  23. }
  24.     package require http
  25.     putquick "PRIVMSG $chan :Requesting and processing information, please wait..."
  26.     set rzyxel ""
  27.     http::config -useragent Mozilla
  28.     if {![catch {http::geturl "http://192.168.1.254:9999/SysStatistics_ADSL.html" -timeout 10000} web]} {
  29.         http::wait $web
  30.         set rzyxel [http::data $web]
  31.         http::cleanup $web
  32.     }
  33.     if {$rzyxel==""} {
  34.         putquick "privmsg $chan :Acquire failed! Try again later."
  35.         return
  36.     }
  37.     if {[regexp "Password" $rzyxel]==1} {
  38.         putquick "privmsg $chan :Router asked to login. Doing it now..."
  39.         set rzyxel ""
  40.         set rquery [http::formatQuery LoginUsername admin LoginPassword ZyXEL+ZyWALL+Series hiddenPassword 33ea114683e0bdcee30763c9723bfcb2 Prestige_Login Login]
  41.         if {![catch {http::geturl "http://192.168.1.254:9999/Forms/rpAuth_1" -query $rquery -timeout 10000} web]} {
  42.             http::wait $web
  43.             set rzyxel [http::data $web]
  44.             http::cleanup $web
  45.         }
  46.         set rzyxel ""
  47.         if {![catch {http::geturl "http://192.168.1.254:9999/SysStatistics_ADSL.html" -timeout 10000} web]} {
  48.             http::wait $web
  49.             set rzyxel [http::data $web]
  50.             http::cleanup $web
  51.         }
  52.         if {$rzyxel==""} {
  53.             putquick "privmsg $chan :Acquire failed! Try again later."
  54.             return
  55.         }
  56.         if {[regexp "Password" $rzyxel]==1} {
  57.             putquick "privmsg $chan :Login incorrect."
  58.             return
  59.         }
  60.     }
  61.    
  62.     #set fd [open zyxel.txt w+]
  63.     #puts $fd "$rzyxel"
  64.     #close $fd
  65. if {($text=="-noise")||($text=="-noiset")} {
  66.   set rzyxel ""
  67.   set rquery [http::formatQuery LineInfoDisplay "" DiagDSLStatus DSL+Line+Status]
  68.   set web [http::geturl "http://192.168.1.254:9999/Forms/DiagADSL_1" -query $rquery -timeout 10000]
  69.   if {![catch {http::geturl "http://192.168.1.254:9999/DiagADSL.html" -timeout 10000} web]} {
  70.     http::wait $web
  71.     set rzyxel [http::data $web]
  72.     http::cleanup $web
  73.   }
  74.   if {$rzyxel==""} {
  75.     putquick "privmsg $chan :Nothing retrieved."
  76.     return 0
  77.   }
  78. set nmu [regexp -inline -all -- {noise margin upstream: (.*?) 0.1db} $rzyxel]
  79. set opd [regexp -inline -all -- {output power downstream: (.*?) 0.1db} $rzyxel]
  80. set aus [regexp -inline -all -- {attenuation upstream: (.*?) 0.1db} $rzyxel]
  81. set nmd [regexp -inline -all -- {noise margin downstream: (.*?) 0.1db} $rzyxel]
  82. set opu [regexp -inline -all -- {output power upstream: (.*?) 0.1db} $rzyxel]
  83. set ads [regexp -inline -all -- {attenuation downstream: (.*?) 0.1db} $rzyxel]
  84. if {$text=="-noise"} {
  85. putquick "privmsg $chan :[lindex $nmu 0]"
  86. putquick "privmsg $chan :[lindex $opd 0]"
  87. putquick "privmsg $chan :[lindex $aus 0]"
  88. putquick "privmsg $chan :[lindex $nmd 0]"
  89. putquick "privmsg $chan :[lindex $opu 0]"
  90. putquick "privmsg $chan :[lindex $ads 0]"
  91. }
  92. if {$text=="-noiset"} {
  93. putquick "privmsg $chan :              Downstream  Upstream"
  94. putquick "privmsg $chan :noise margin     [expr {[lindex $nmd 1] *0.1}]       [expr {[lindex $nmu 1] *0.1}]"
  95. putquick "privmsg $chan :attenuation      [expr {[lindex $ads 1] *0.1}]       [expr {[lindex $aus 1] *0.1}]"
  96. putquick "privmsg $chan :output power     [expr {[lindex $opd 1] *0.1}]       [expr {[lindex $opu 1] *0.1}]"
  97. }
  98.  
  99.  return 0
  100. }
  101.  
  102.     regsub -all -- {\{} $rzyxel {(} rzyxel
  103.     regsub -all -- {\}} $rzyxel {)} rzyxel
  104.     regsub -all -- {\"} $rzyxel {'} rzyxel
  105.     regsub -all -- {\n} $rzyxel "" rzyxel
  106.     set SystemUpTime [string trim [lindex [regexp -inline -- {<td width='30%'> System up Time: </td><td width='70%'> <b>(.*?)</b> </td>} $rzyxel] 1]]
  107.     set CPUUsage [string trim [lindex [regexp -inline -- {<td>CPU Usage:</td><td><b>(.*?)</b></td>} $rzyxel] 1]]
  108.     set MemoryUsage [string trim [lindex [regexp -inline -- {<td>Memory Usage:</td><td><b>(.*?)</b> </td>} $rzyxel] 1]]
  109.     set LinkStatus [string trim [lindex [regexp -inline -- {<td width='30%'> Link Status:</td><td width='71%'><b>(.*?)</b></td></tr><tr>} $rzyxel] 1]]
  110.     set WANIP [string trim [lindex [regexp -inline -- {<td>WAN IP Address:</td><td><b>(.*?)</b></td></tr><tr>} $rzyxel] 1]]
  111.     set UpstremSpeed [string trim [lindex [regexp -inline -- {<td>Upstream Speed:</td><td><b>(.*?)</b></td></tr><tr>} $rzyxel] 1]]
  112.     set DownstreamSpeed [string trim [lindex [regexp -inline -- {<td>Downstream Speed: </td><td><b>(.*?)</b></td></tr><tr>} $rzyxel] 1]]
  113.     regsub -all -- {%} $CPUUsage {} cpuusagen
  114.     regsub -all -- {%} $MemoryUsage {} memoryusagen
  115.     set linkstat [lindex [regexp -inline -- {<td class='tabcolor2' > <div align=center>  1(.*?)</tr>} $rzyxel] 0]
  116.     regsub -all -- { } $linkstat "" linkstat
  117.     regsub -all -- {</tr>} $linkstat "" linkstat
  118.     regsub -all -- {<tdclass='tabcolor2'><divalign=center>} $linkstat "" linkstat
  119.     regsub -all -- {</div></td>} $linkstat " " linkstat
  120.     set lanstat [lindex [regexp -inline -- {<td class='tabcolor2'> <div align=center> Ethernet(.*?)</table>} $rzyxel] 0]
  121.     regsub -all -- { } $lanstat "" lanstat
  122.     regsub -all -- {</tr>} $lanstat "" lanstat
  123.     regsub -all -- {<tdclass='tabcolor2'><divalign=center>} $lanstat "" lanstat
  124.     regsub -all -- {<tr><tdclass='TableItem'><divalign=center>} $lanstat "" lanstat
  125.     regsub -all -- {<td><divalign=center>} $lanstat "" lanstat
  126.     regsub -all -- {</div></td>} $lanstat " " lanstat
  127.     regsub -all -- {</table>} $lanstat "" lanstat
  128.     set systemuptimehms [split $SystemUpTime ":"]
  129.     set systemuptimesecs [expr [regsub {^0*(.+)} [lindex $systemuptimehms 0] {\1}]*3600+[regsub {^0*(.+)} [lindex $systemuptimehms 1] {\1}]*60+[regsub {^0*(.+)} [lindex $systemuptimehms 2] {\1}]]
  130.        
  131. set routerweb [http::geturl "http://192.168.1.254:9999/home.html" -timeout 3000]
  132. http::wait $routerweb
  133. set routermodeldata [http::data $routerweb]
  134. http::cleanup $routerweb
  135. regsub -all {\n} $routermodeldata "" routermodeldata
  136. set rzmodel ""
  137. set rzmodel [lindex [regexp -all -inline -- {<td>Model Number: </td><td colspan=\"2\" class=\"ds_text\">(.*?)</td></tr>} $routermodeldata] 1]
  138. set rdslmode [lindex [regexp -all -inline -- {DSL Mode: \</td\>\<td colspan=\"2\" class=\"ds_text\"\>(.*?)</td>} $routermodeldata] 1]
  139.     if {($text=="") || ([lsearch -nocase $text "-s"]>=0)} {
  140.         putquick "PRIVMSG $chan :\0031,14\002 System Monitor \002\003 \0037\002Model Number:\002\00311 ZyXEL$rzmodel \0037\002System Up Time:\002\00311 $SystemUpTime ([conv_s_wdhms $systemuptimesecs])  \002\0037CPU Usage:\002\003 [usagebar $cpuusagen 20]  \002\0037Memory Usage:\002\003 [usagebar $memoryusagen 20]\003"
  141.     }
  142.     if {($text=="") || ([lsearch -nocase $text "-w"]>=0)} {
  143.         putquick "PRIVMSG $chan :\0031,14\002 WAN Port Statistics \002\003 \0037\002Link Status:\002\00311 $LinkStatus  \002\0037WAN IP Address:\002\00311 $WANIP  \002\0037Upstream Speed:\002\00311 $UpstremSpeed  \002\0037Downstream Speed:\002\00311 $DownstreamSpeed  \002\0037DSL Modulation:\002\00311$rdslmode\003"
  144.         putquick "PRIVMSG $chan :\002\0037Node-Link:\002\00311 [lindex $linkstat 0]  \002\0037Status:\002\00311 [lindex $linkstat 1]  \002\0037TxPkts:\002\00311 [lindex $linkstat 2]  \002\0037RxPkts:\002\00311 [lindex $linkstat 3]  \002\0037Errors:\002\00311 [lindex $linkstat 4]  \002\0037Tx B/s:\002\00311 [lindex $linkstat 5]  \002\0037Rx B/s:\002\00311 [lindex $linkstat 6]  \002\0037Up Time:\002\00311 [lindex $linkstat 7]"
  145.     }
  146.     if {($text=="") || ([lsearch -nocase $text "-l"]>=0)} {
  147.         putquick "PRIVMSG $chan :\0031,14\002                 LAN Port Statistics                \002\003"
  148.         putquick "PRIVMSG $chan :Interface  |Status     |TxPkts     |RxPkts     |Collisions "
  149.         putquick "PRIVMSG $chan :[format "%-11s|%-11s|%11s|%11s|%11s" [lindex $lanstat 0] [lindex $lanstat 1] [lindex $lanstat 2] [lindex $lanstat 3] [lindex $lanstat 4]]"
  150.         putquick "PRIVMSG $chan :[format "%-11s|%-11s|%11s|%11s|%11s" [lindex $lanstat 5] [lindex $lanstat 6] [lindex $lanstat 7] [lindex $lanstat 8] [lindex $lanstat 9]]"
  151.                return
  152.     }
  153. }
  154.  
  155. proc usagebar {percentage barwidth} {
  156.     #set barx "[expr $barwidth * round($percentage) / 100]"
  157.     #if {$barx == "0"} {set barx "1"}
  158.     #set thebar "\00312[string repeat "█" $barx]\003"
  159.     #set thebar "${thebar}\0032,1[string repeat "█" [expr $barwidth - $barx]]\003"
  160.     #return $thebar
  161.     return [pbardraw 20 [expr round($percentage)] 12 2 0 $percentage% ]
  162. }
  163.  
  164. proc conv_s_wdhms {duration} {
  165.    set outputtext ""
  166.     set zw [expr $duration/604800]
  167.    set duration [expr $duration-$zw*604800]
  168.    set zd [expr $duration/86400]
  169.    set duration [expr $duration-$zd*86400]
  170.    set zh [expr $duration/3600]
  171.    set duration [expr $duration-$zh*3600]
  172.    set zm [expr $duration/60]
  173.    set duration [expr $duration-$zm*60]
  174.    set zs $duration
  175.    if {$zw == 1} {append outputtext $zw "wk "}
  176.    if {$zw > 1} {append outputtext $zw "wks "}
  177.    if {$zd == 1} {append outputtext $zd "day "}
  178.    if {$zd > 1} {append outputtext $zd "days "}
  179.    if {$zh == 1} {append outputtext $zh "hr "}
  180.    if {$zh > 1} {append outputtext $zh "hrs "}
  181.    if {$zm == 1} {append outputtext $zm "min "}
  182.    if {$zm > 1} {append outputtext $zm "mins "}
  183.    if {$zs == 1} {append outputtext $zs "sec"}
  184.    if {$zs > 1} {append outputtext $zs "secs"}
  185.    return $outputtext
  186. }
RAW Paste Data