Posted to tcl by aspect at Thu Apr 02 23:42:52 GMT 2015view raw

  1. #!/usr/bin/expect -f
  2.  
  3. set timeout 30
  4. spawn telnet {*}$argv
  5. match_max 100000
  6.  
  7. # handle early disconnections
  8. expect_after {
  9. eof {
  10. error "Unexpected end of file!"
  11. }
  12. timeout {
  13. error "Server took too long to respond!"
  14. }
  15. }
  16.  
  17. # try multiple passwords:
  18. set passwords {"Pass1" "" "Pass3" "Pass4"}
  19. set idx -1
  20. while {1} {
  21. incr idx
  22. if {$idx >= [llength $passwords]} {
  23. error "Failed to log in!"
  24. }
  25. expect {
  26. "word:" {
  27. send [lindex $passwords $idx]\n
  28. }
  29. -exact in$ {
  30. break
  31. }
  32. }
  33. }
  34. puts "Logged in with [lindex $passwords $idx]"
  35.  
  36. # login already expected a prompt
  37. send "set ethernetDoSThrottleShutoff 1 1 1\r"
  38. expect -exact in$
  39. send "get ethernetDoSThrottleShutoff\r"
  40. expect -exact in$
  41. send "exit\r"
  42. expect eof ;# this bit is important!
  43.