Why do I need to manually input username when connecting to switch with a python script?

66 views Asked by At

I'm converting a VB script that connects to a switch through SecureCRT into Python3. The original script contains:

crt.Session.Connect " /SSH2 /L " & user & " /PASSWORD " & pass & " /P 22" & " /ACCEPTHOSTKEYS " & ip

This script runs this command and continues through the rest of code, automated as it should be.

In my version, I use the line:

crt.Session.Connect("SSH2/L %s /PASSWORD %s /P 22 /ACCEPTHOSTKEYS %s" % (user,pass,ip))

My script runs up until this point where CRT displays:

#Banner
Please enter login information for #ip.
Username:

And it hangs there. I can manually type in user and the script continues on as expected from that point. Interrupting the script shows that it is hanging on this line, presumably waiting for an input? How do I ensure the script sends the username as part of the command instead of requiring the user's input?

1

There are 1 answers

0
Shadomew On

Figured it out, and it's embarrassingly obvious. The line in python should be

crt.Session.Connect("/SSH2 /L %s /PASSWORD %s /P 22 /ACCEPTHOSTKEYS %s" % (user,pw,ip))

instead of

crt.Session.Connect("SSH2/L %s /PASSWORD %s /P 22 /ACCEPTHOSTKEYS %s" % (user,pw,ip))