Advertisement
JS_basted

reconf authentication

Feb 14th, 2020
1,208
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/expect
  2.  
  3. # Set up various other variables here ($user, $password)
  4. set timeout 15
  5. set password "Cisco_123"
  6. set f_read [open ./switches r]
  7.  
  8. # itarate over the switches
  9. while {[gets $f_read device] != -1} {
  10.    spawn telnet $device
  11.    expect {
  12.         timeout { continue }
  13.         "Connection refused" {continue }
  14.         "Username:" { continue }
  15.         "Password:" { send "$password\r"; }
  16.         "*>" { sleep 2 }
  17.     }
  18.    expect "*>"
  19.    send "enable\r"
  20.    expect "Password:"
  21.    send "$password\r"
  22.    expect "*#"
  23.    send "copy tftp://192.168.200.199/reconf-auth.cfg running-config\r\r"
  24.    expect "*#"
  25.    sleep 5
  26.    send "write\r"
  27.    expect "*#"
  28.    sleep 10
  29.    send "logout\r"
  30.    expect eof
  31. }
  32. # end
Advertisement
RAW Paste Data Copied
Advertisement