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