Chinaunix首页 | 论坛 | 博客

qsh

  • 博客访问: 3955345
  • 博文数量: 1015
  • 博客积分: 15904
  • 博客等级: 上将
  • 技术积分: 8572
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-04 19:16
文章分类

全部博文(1015)

文章存档

2019年(1)

2017年(1)

2016年(19)

2015年(27)

2014年(30)

2013年(95)

2012年(199)

2011年(72)

2010年(109)

2009年(166)

2008年(296)

分类: 系统运维

2012-04-02 16:05:43

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
 
阅读(2304) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~