Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-20-2021, 11:46 AM
arortizg arortizg is offline
Registered User
 
Join Date: Mar 2021
Posts: 1
Unhappy Re-attempt SSH login.

Hello Forum.


Hope all of you are doing fine.


I'm having this problem which I'm sure you have already encountered and fix, but I haven't been able to find an answer yet in the forum.


I'm using this script to logging into multiple devices through SSH2. The problems relies when the first Username and Password fail, then I attempt to use a second Username and Password but the programs seems to never reach that part of the code because a Error window pops saying "Keyboard-Interactive authentication with the SSH2 server failed" and wont let the "else" to execute, any idea on how to make the program try another set of username and password if the the first one failed?


Code:
# $language = "python"
# $interface = "1.0"

# This script demonstrates how to open a text file and read it line by
# line to a server.

# CopyToClipboard.py


devices = ["10.238.10.10",
"10.238.10.11",
"10.238.10.12"
]


def mainConnection():

    for dev in devices:

        try:
            crt.Session.ConnectInTab("/SSH2 /L USERNAME1 /PASSWORD PASSWORD1 " + dev)
        except ScriptError:
            error = crt.GetLastErrorMessage()

        if crt.Session.Connected == True:
            crt.Dialog.MessageBox("Connection successful " )
        else:
            ###This is the line of code that wont execute if the first username and pass fail.
            crt.Session.ConnectInTab("/SSH2 /L USERNAME2 /PASSWORD PASSWORD2 " + dev)



def main():
    mainConnection()
    #sendingCommand()


        


main()
Reply With Quote
  #2  
Old 03-21-2021, 01:06 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,596
Hi arortizg,

The ConnectInTab() method takes an optional parameter which determines whether the call fails silently or raises an exception:
Quote:
Remarks

Takes the same arguments as Connect. This also returns a Tab object.

The ConnectInTab method also takes two optional parameters (True or False). The first determines whether or not the script should wait for the connection to fully authenticate before continuing. The first parameter only applies to SSH1 and SSH2 connections. The second optional parameter specifies whether the call fails silently or raises an exception. If the second parameter is False and the connection attempt fails, an exception is raised and the method returns an empty object. If the second parameter is True and the connection attempt fails, the method returns a valid Tab object, which can then be used to check for connection status in order to determine if the connection attempt was successful.
And then a relevant line of info from Connect() method:
Quote:
The Connect method also takes an optional parameter (True or False) that specifies whether or not to suppress pop-up messages. This parameter defaults to False (don't suppress).
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 03-31-2021, 09:49 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,596
Hi arortizg,

Also, you will likely need to enable the Display logon prompts in terminal window option in the Connection / Logon Actions category of Session Options. You would make that change to Default session since you are making ad hoc connections in your script.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Tags
failed , multiple log , python , ssh2


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:33 AM.