Guest User

Untitled

a guest
Dec 3rd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.21 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. expect_after -re {Bad username|Login incorrect} {
  19.         send_user -- "$ip: auth problem. last output:\n $expect_out(buffer)\n=========\n"
  20.         catch {exp_close}
  21.         continue
  22.     } -re {Unable to connect to remote host|Connection closed by foreign host} {
  23.         send_user -- "$ip: connection problem. last output:\n $expect_out(buffer)\n=========\n"
  24.         catch {exp_close}
  25.         continue
  26.     } timeout {
  27.         send_user "$ip: timeout"
  28.         catch {exp_close}
  29.         continue
  30.     } eof {
  31.         send_user "$ip: close connection. last output:\n $expect_out(buffer)\n=======\n"
  32.         continue
  33.     }
  34.  
  35.  
  36. foreach ip $ip_list {
  37.         if {$ip != ""} {
  38.                 send_user "telnet to this host: $ip\n"
  39.  
  40.                 # Connect
  41.                 spawn telnet $ip
  42.  
  43.                 # router user name
  44.                 set name "admin"
  45.  
  46.                 # router password
  47.                 set pass "1234"
  48.  
  49.                 # Read command as arg to this script
  50.                 set routercmd [lindex $argv 0]
  51.  
  52.                 # send username & password
  53.                 expect -re {ogin|sername} {
  54.                         send -- "$name\r"
  55.                     }
  56.  
  57.                 expect {assword} {
  58.                         send -- "$pass\r"
  59.                     }
  60.  
  61.                 # expect one of these strings and take an action depending which one comes
  62.                 # replace "Login incorrect" with whatever message your router sends
  63.                 expect {Do you want to spawn a shell instead} {
  64.                         send "y\n"
  65.  
  66.                         # execute command , supposed we r using ash at aztech router
  67.                         expect -re {#|\$} {
  68.                             send -- "$routercmd\r"
  69.                         }
  70.                     }
  71.                 send_user "end processing host: $ip\n\n"
  72.                 # close the child process
  73.                 catch {exp_close}
  74.         }
  75. }
Add Comment
Please, Sign In to add comment