Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/expect -f
- set timeout 5
- set load_fh [open "targets.txt" r]
- set ip_list [split [read $load_fh] "\n"]
- close $load_fh
- # router user name
- set name "admin"
- # router password
- set pass "1234"
- # Read command as arg to this script
- set routercmd [lindex $argv 0]
- foreach ip $ip_list {
- if {$ip != ""} {
- send_user "telnet to this host: $ip\n"
- # Connect
- spawn telnet $ip
- # router user name
- set name "admin"
- # router password
- set pass "1234"
- # Read command as arg to this script
- set routercmd [lindex $argv 0]
- # send username & password
- expect -re {Login|Username} {
- send -- "$name\r"
- } -re {Unable to connect to remote host|Connection closed by foreign host} {
- send_user -- "$ip: connection problem. last output:\n $expect_out(buffer)\n=========\n"
- exp_close
- continue
- } timeout {
- send_user "$ip: timeout. last output:\n $expect_out(buffer)\n=======\n"
- exp_close
- continue
- } eof {
- send_user "$ip: close connection. last output:\n $expect_out(buffer)\n=======\n"
- continue
- }
- expect {assword} {
- send -- "$pass\r"
- } -re {Bad username|Login incorrect} {
- send_user -- "$ip: auth problem. last output:\n $expect_out(buffer)\n=========\n"
- exp_close
- continue
- } -re {Unable to connect to remote host|Connection closed by foreign host} {
- send_user -- "$ip: connection problem. last output:\n $expect_out(buffer)\n=========\n"
- exp_close
- continue
- } timeout {
- send_user "$ip: timeout. last output:\n $expect_out(buffer)\n=======\n"
- exp_close
- continue
- } eof {
- send_user "$ip: close connection. last output:\n $expect_out(buffer)\n=======\n"
- continue
- }
- # expect one of these strings and take an action depending which one comes
- # replace "Login incorrect" with whatever message your router sends
- expect -re {Bad username|Login incorrect} {
- send_user -- "$ip: auth problem. last output:\n $expect_out(buffer)\n=========\n"
- exp_close
- continue
- } {Do you want to spawn a shell instead} {
- send "y\n"
- # execute command , supposed we r using ash at aztech router
- expect -re {#|\$} {
- send -- "$routercmd\r"
- }
- }
- send_user "end processing host: $ip\n\n"
- # close the child process
- exp_close
- }
- }
Add Comment
Please, Sign In to add comment