View Single Post
  #1  
Old 02-11-2009, 03:21 PM
1720 1720 is offline
Registered User
 
Join Date: Jul 2007
Posts: 13
Multiple methods of connecting to device

I am trying to use SecureCRT to connect to a device first trying ssh and if it fails, then use telnet. The script runs fine if the device supports ssh, but if it does not and only supports ssh, I am getting a Runtime error. Here is my code -
<CODE>
# $language = "VBScript"
# $interface = "1.0"

Sub Main

crt.Screen.Synchronous = TRUE

Dim prompt
prompt = "Password: "

Dim device
device = crt.Arguments(0)

Dim user_name
user_name = crt.Dialog.Prompt("Enter your TACACS userID ", user_name, "TACACS Login",False)

Dim passwd
passwd = crt.Dialog.Prompt("Enter your TACACS Password ", passwd, "TACACS Password",True)


cmd = "/SSH2 /L " & user_name & " /PASSWORD " & passwd & " " & device

crt.Session.Connect cmd

if crt.Screen.WaitForString(device, 4) = True then
crt.window.caption = device
' crt.Screen.Send passwd & vbCr
else
crt.Screen.Send "telnet " & device & chr(13)
crt.Screen.WaitForString "Username:"
crt.Screen.Send user_name & vbCr
crt.Screen.WaitForString "Password:"
crt.Screen.Send passwd & vbCr
end if
End Sub
<CODE>
Reply With Quote