|
#1
|
|||
|
|||
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> |
#2
|
||||
|
||||
Hello,
It sounds like you're saying that SSH works fine but that the telnet fallback is causing an error. I'd like to verify that I understand how the script is called and the logic involved. You call the script using a command like the following: SecureCRT.exe /S "Session Name" /SCRIPT "c:\Scripts\ProtocolFallbackScript.vbs" /ARG "devicename"The script puts the devicename into the "device" variable and tries to connect using SSH2. If SecureCRT detects the string in the device variable (within 4 seconds) then you're connected. Otherwise you want to run connect using the Telnet protocol. I think that the following line will cause a runtime error because you're not connected: crt.Screen.Send "telnet " & device & chr(13)The CRT Scripting Runtime error probably says "Error: Screen.Send: not connected". Is this summary correct?
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#3
|
|||
|
|||
Hi Mike,
You are pretty much correct with your summary. It first attempts to use ssh, and if fails within 4 seconds, it tries to use telnet or atleast that is the intent of the script. Your statement on how I call the script is also correct. I have attached a screenshot of the error window. But basically it is - CRT Scripting Runtime Error Error: Connection failed File:..... Line: 23 |
#4
|
||||
|
||||
Hi,
Thanks for confirming that you're wanting to use a protocol fallback. The current problem looks like it's coming as a result of not being able to connect using SSH2. If you were to trap the error (On Error Resume Next) then this may not happen and the script should continue. However, there would still be the issue of trying to connect to a telnet server using Crt.Screen.Send. I ran some tests and modified your code slightly. In my tests the script seemed to work as I think you're wanting. The modified code is below. 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 ", cmd = "/SSH2 /L " & user_name & " /PASSWORD " & passwd & " " & device ' Prevent an error from stopping script execution On Error Resume Next crt.Session.Connect cmd if crt.Screen.WaitForString(device, 1) <> True then cmd = "/TELNET " & device crt.Session.Connect cmd crt.Screen.WaitForString "Username:" crt.Screen.Send user_name & vbCr crt.Screen.WaitForString "Password:" crt.Screen.Send passwd & vbCr else crt.window.caption = device end if End Sub Does the modified script above work any better for you? Do you think you might be able to modify the ConnectionProtocolFallback-PromptForTarget script to work for your particular goal?
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#5
|
|||
|
|||
Hi Mike,
Thank-you so much. The script works fine. I also looked at the attachment you sent and it looks very useful. I am probably going to try it out on Monday to see how it works. Once again, thank-you so much. |
#6
|
||||
|
||||
Great - I'm glad to hear the modified script worked. Thanks for posting to let us know.
![]()
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|