Hi all
I have on script which tries all connection (Telnet, SSH1 and SSH2) which supply username, password and enable password, the script is keep prompting me for enable password and halt execution
Dim strUsername ' username, this can be changed at runtime
Dim strPassword ' password
Dim strLogPath ' where the logs should be stored
Dim arrHostnames ' an array of hostnames to get configs from
Dim strCurrentHostname
Dim strPrompt
Dim StrEnable
strLogPath = "C:\Users\bono\Desktop\Secure Script\"
strHostnamesFilePath = "C:\Users\bono\Desktop\Secure Script\hostnames.txt"
Dim g_shell
ConnectWithFallback
Sub ConnectWithFallback()
strUsername = "xxxx"
strPassword = "xxxxx"
StrEnable = "xxxxxx"
Set g_shell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strHostnamesFilePath, ForReading)
Const ForReading = 1
i = 0
Do Until objFile.AtEndOfStream
strCurrentHostname = objFile.ReadLine
strPrompt = strCurrentHostname & "#"
i = i + 1
if crt.Session.Connected then
crt.Session.Disconnect
end if
crt.Screen.Synchronous = true
Dim strSecureShellIdent
If Not CheckRemoteSSHConnectivity(strSecureShellIdent) then
ConnectWithTelnetProtocol
else
if Instr(strSecureShellIdent, "SSH-2") > 0 then
ConnectWithSSH2Protocol
ElseIf Instr(strSecureShellIdent, "SSH-1.99") > 0 then
ConnectWithSSH2Protocol
Elseif Instr(strSecureShellIdent, "SSH-1") > 0 then
ConnectWithSSH1Protocol
end if
end if
crt.Screen.Synchronous = True
crt.Session.LogFileName = strLogPath & strCurrentHostname & ".txt"
crt.Session.Log True
crt.Screen.WaitForString strPrompt, 1
crt.Screen.Send "terminal len 0" & vbCr
crt.Session.Log False
crt.Screen.Synchronous = False
crt.Session.Disconnect
Loop
objFile.Close
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function CheckRemoteSSHConnectivity(byRef strIdent)
On Error Resume Next
ConnectionString = "/telnet " & strCurrentHostname & " 22"
crt.Session.Connect ConnectionString
if Err.Number <> 0 then
exit function
end if
crt.Screen.Synchronous = True
nResult = crt.Screen.WaitForString("SSH-", 3)
nResult = crt.Screen.WaitForString("-", 3)
if nResult = 0 then
crt.Session.Disconnect
exit function
end if
strIdent = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
crt.Session.Disconnect
CheckRemoteSSHConnectivity = True
On Error Goto 0
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ConnectWithTelnetProtocol()
ConnectionString = "/telnet "& strCurrentHostname
crt.Session.Connect ConnectionString
crt.Screen.WaitForString "Username:"
crt.Screen.Send strUsername & vbcr
crt.Screen.WaitForString "Password:"
crt.Screen.Send strPassword & vbcr
crt.Screen.SendKeys "en" & vbcr
crt.Screen.SendKeys strEnable & vbcr
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ConnectWithSSH1Protocol()
ConnectionString = "/SSH1 /L " & strUsername & " /PASSWORD " & strPassword & " /AcceptHostKeys "& strCurrentHostname
crt.Session.Connect ConnectionString
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ConnectWithSSH2Protocol()
ConnectionString = "/SSH2 /AcceptHostKeys "& strCurrentHostname
crt.Session.Connect ConnectionString
crt.Screen.WaitForString "Username:"
crt.Screen.Send strUsername & vbcr
crt.Screen.WaitForString "Password:"
crt.Screen.Send strPassword & vbcr
crt.Screen.SendKeys "en" & vbcr
crt.Screen.SendKeys strEnable & vbcr
End Function
阅读(2438) | 评论(0) | 转发(0) |