VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   VBS Script showing error (https://forums.vandyke.com/showthread.php?t=13524)

vikram1840 05-03-2019 04:49 AM

VBS Script showing error
 
Hello Experts,
I am using securecrt8.5 and want to connect session through VBS script.
In general while connecting the session manually it ask about username,pswd and neId as well and after putting all info it get connect. But the same while i am doing through VBS script it showing error of connection failed.

Point to note-required server is having port other than 22 and apart from it required neId as well. so pleas guide me to run this script succfully.


Code:

# $language = "VBScript"
# $interface = "1.0"

  Sub Main

    Dim pass
    Dim session_name
    Dim password
    Dim user_name
    Dim log_file

    Hostname = "100.100.10.10"
    user_name = "usernm"
    password = "pswd"
    neId = "ABCD-GHIJK-LMNP"
    log_file = "C:\Users\vikramku\Desktop\OSS Connect Macro\Logs\logs.txt"

    crt.Session.LogFileName = log_file
    crt.Session.Log True

    cmd = "/SSH2 /P 8022 /L " & user_name & "/PASSWORD " & password & "/neId" & neId &  " /C 3DES /M MD5 " & Hostname
    crt.Session.Connect cmd

    crt.Screen.send "amos ABCD" & vbCr
    login = crt.Screen.WaitForStrings(">", "Not OK")
    If login = 2 Then
      MsgBox "Information : ABCD is not Reachable, Please click ok to continue.", vbExclamation
    Else
      crt.Screen.send "lt all" & vbCr
      crt.Screen.send "st cell" & vbCr
      crt.screen.send "exit" & vbCr
      crt.Screen.WaitForString "Bye..."
    End if

    crt.screen.send "exit" & vbCr
    crt.screen.synchronous = false
    crt.Screen.WaitForString "logout"

    crt.Session.Log False
    crt.Session.Disconnect
    crt.Quit

  End Sub


jdev 05-03-2019 11:03 AM

1 Attachment(s)
Dear vikram1840,

Please use [CODE] and [/CODE] tags around your script code so that indentation/formatting is not lost through HTML browser space aggregation; for example:
https://forums.vandyke.com/attachmen...achmentid=1688
With respect to the code you're writing and the error that occurs, what is the exact wording of the error/failure message(s) that you see?

To display debugging/troubleshooting info for connection attempts, you can set Trace Level to 1 for such info to be displayed to the terminal window before you make the call to Connect().

Also, unless your user_name variable's value includes a trailing space character, you're ending up with the /PASSWORD component immediately concatenated to the end of your username, which could be a source of problems for you (see the first section of your code marked in red below). Imagine this working?
SecureCRT /SSH2 /L usernm/Password p4$$w0rd/neIdblahblahblah 100.100.10.10
No. That won't work... it will start the auth process as user "usernm/Password" and all the rest of the command line will be gibberish because SecureCRT can only then assume that p4$$w0rd/neIDblahblahblah is the host name.

In addition, I have to question... why are you limiting the connection to only being able to use the deprecated/old 3DES cipher and MD5 MAC? (see the second section of your code marked in red below). If you're connecting to any newer hosts, that cipher and/or MAC may not be supported. I'd suggest eliminating this from your code unless you somehow want to the connection to fail or use the weakest of all algorithms.

Code:

    .
    .
    .
    crt.Session.LogFileName = log_file
    crt.Session.Log True

    ' Turn on Trace Options before attempting the connection
    ' so that troubleshooting/debugging info can be displayed
    ' to the terminal screen:
    crt.Session.Config.SetOption "Trace Level", 1


    cmd = "/SSH2 /P 8022 /L " & user_name & "/PASSWORD " & password & "/neId" & neId &  " /C 3DES /M MD5 " & Hostname
    crt.Session.Connect cmd

    crt.Screen.send "amos ABCD" & vbCr
    .
    .
    .


--Jake

vikram1840 05-10-2019 02:00 AM

VBS Script showing error
 
Hello JDev,

Thanks for your reply.
I have got solution.
Issue was with this part deprecated/old 3DES cipher and MD5 MAC.
When I was considering this part in my code it selected only 3DES in ciper and MD5 in MAC while new host was not supporting other ciper and MAC so it reflected error.

Now I remove this part and code works.

Code:

crt.Session.LogFileName = log_file
    crt.Session.Log True
        crt.Session.Config.SetOption "Trace Level", 1

  cmd = "/SSH2 /L " & session_name & " /PASSWORD " & password & " " & pass
    crt.Session.Connect cmd


jdev 05-10-2019 10:05 AM

Quote:

Originally Posted by vikram1840 (Post 51474)
...new host was not supporting other ciper and MAC so it reflected error. Now I remove this part and code works.

Code:

crt.Session.LogFileName = log_file
    crt.Session.Log True
        crt.Session.Config.SetOption "Trace Level", 1

  cmd = "/SSH2 /L " & session_name & " /PASSWORD " & password & " " & pass
    crt.Session.Connect cmd


Glad to know you have a solution in place now.

Very nice use of [CODE][/CODE] tags! :)

--Jake


All times are GMT -6. The time now is 06:37 PM.