Sub Main
Const username = "" ' Username to use for login
Const password = "" ' Password for corresponding user
Const loginPass = "" ' Password to use for password only login (aka no aaa new-model)
Const oldEnablePass = "" ' The current enable Password
Const newLoginPass = "" ' New password to set for telnet and console lines
Const newEnablePass = "" ' New Enable password to set
Const DEVICE_FILE_PATH = "c:\scripts\devices.txt"
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fil
Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)
Dim ip
Dim name
Dim protocol
Dim line
Dim cnxnString
While Not fil.AtEndOfStream
line = fil.ReadLine
name = Split(line, ";")(0)
ip = Split(line, ";")(1)
protocol = Split(line, ";")(2)
Select Case protocol
Case "Telnet"
cnxnString = "/TELNET " & ip & " 23"
Case "SSH2"
cnxnString = "/SSH2 /L " & username & " /PASSWORD " & password & " /C 3DES /M MD5 " & ip
Case "SSH1"
cnxnString = "/SSH1 /L " & username & " /PASSWORD " & password & " /C 3DES /M MD5 " & ip
End Select
' Connect
crt.Screen.Synchronous = True
crt.Session.Connect cnxnString
If protocol = "Telnet" Then
Dim index
index = crt.Screen.WaitForStrings("Username:", "Password:")
If index = 1 Then
crt.Screen.Send username & vbCr
crt.Screen.WaitForString "Password:"
crt.Screen.Send password & vbCr
Else If index = 2
crt.Screen.Send loginPass & vbCr
End If
End If
' Enable
crt.Screen.WaitForString ">"
crt.Screen.Send "en" & vbCr
crt.Screen.WaitForString "Password:"
crt.Screen.Send oldEnablePass & vbCr
crt.Screen.WaitForString "#"
crt.Screen.Send "conf t" & vbCr
crt.Screen.WaitForString "(config)#"
' change enable password
crt.Screen.Send "enable secret " & newEnablePass & vbCr
crt.Screen.WaitForString "(config)#"
' Change telnet password
crt.Screen.Send "line vty 0 15" & vbCr
crt.Screen.WaitForString "(config-line)#"
crt.Screen.Send "password " & newLoginPass & vbCr
crt.Screen.WaitForString "(config-line)#"
crt.Screen.Send "exit" & vbCr
crt.Screen.WaitForString "(config)#"
' Change console password
crt.Screen.Send "line con 0" & vbCr
crt.Screen.WaitForString "(config-line)#"
crt.Screen.Send "password " & newLoginPass & vbCr
crt.Screen.WaitForString "(config-line)#"
crt.Screen.Send "exit" & vbCr
crt.Screen.WaitForString "(config)#"
' Save
crt.Screen.Send "exit" & vbCr
crt.Screen.WaitForString "#"
crt.Screen.Send "copy run start" & vbCr
crt.Screen.WaitForString "startup-config"
crt.Screen.Send vbCr
crt.Screen.WaitForString "#"
crt.Screen.Synchronous = False
crt.Session.Disconnect
Wend
fil.Close
End Sub