Guest User

Untitled

a guest
Dec 3rd, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.82 KB | None | 0 0
  1. #!/usr/bin/expect -f
  2.  
  3. set timeout 5
  4.  
  5. set load_fh [open "targets.txt" r]
  6. set ip_list [split [read $load_fh] "\n"]
  7. close $load_fh
  8.  
  9. # router user name
  10. set name "admin"
  11.  
  12. # router password
  13. set pass "1234"
  14.  
  15. # Read command as arg to this script
  16. set routercmd [lindex $argv 0]
  17.  
  18. foreach ip $ip_list {
  19.         if {$ip != ""} {
  20.                 send_user "telnet to this host: $ip\n"
  21.  
  22.                 # Connect
  23.                 spawn telnet $ip
  24.  
  25.                 # router user name
  26.                 set name "admin"
  27.  
  28.                 # router password
  29.                 set pass "1234"
  30.  
  31.                 # Read command as arg to this script
  32.                 set routercmd [lindex $argv 0]
  33.  
  34.                 # send username & password
  35. expect {Username:} {
  36.         send -- "$name\r"
  37.     } {Unable to connect to remote host} {
  38.         send_user -- $expect_out(buffer)
  39.         exp_close
  40.         continue
  41.     } timeout {
  42.         send_user "timeout"
  43.         exp_close
  44.         continue
  45.     }
  46.                 expect "Password:"
  47.                 send -- "$pass\r"
  48.  
  49.                 # expect one of these strings and take an action depending which one comes
  50.                 # replace "Login incorrect" with whatever message your router sends
  51.                 expect {
  52.                     "Do you want to spawn a shell instead?" {
  53.                         send "y\n"
  54.  
  55.                         # execute command , supposed we r using ash at aztech router
  56.                         expect "# "
  57.                         send -- "$routercmd\r"
  58.                     }
  59.                     "Login incorrect" {
  60.                         puts "Login to $ip failed!"
  61.                     }
  62.                 }
  63.                 send_user "end processing host: $ip\n\n"
  64.                 # close the child process
  65.                 exp_close
  66.         }
  67. }
Add Comment
Please, Sign In to add comment