cancel
Showing results for 
Search instead for 
Did you mean: 

[Python] Whats the best way to get the password prompt

[Python] Whats the best way to get the password prompt

Radoje_Stojisic
New Contributor
I am trying to make a little python script which is able to update the switches. However I am little confused by the "Getting started Python guide". Is there any option to let the python script enter the password for the remote connection ?

Thanks 
6 REPLIES 6

Kevin_Kim
Extreme Employee
Another way to skin a cat. Telnet session to control VR will open although telnet is globally disabled.

import subprocess
import time

p = subprocess.Popen(['telnet', '-v', '1', '127.0.0.1'], stdin = subprocess.PIPE)
print >> p.stdin, 'admin'
print >> p.stdin, '\n'
print >> p.stdin, 'scp2 scpuser@10.0.0.1:bd8800-15.7.2.9.xos bd8800-15.7.2.9.xos'
time.sleep(3)
print >> p.stdin, 'scppw'
time.sleep(60)
p.terminate()

Erik_Auerswald
Contributor II
Did you consider using SSH with key-based authentication? This way you can execute any command on the switch without the need to enter a password, as long as the private key is available to the SSH client (usually using ssh-agent).

OscarK
Extreme Employee
Something like below ?
host=host
user=user
password=password
prompt=re.compile(r'\S+\d+\s[#>]\s')
loginprompt=r"login"
passwordprompt=r"assword"
failedlogin = r"Login incorrect"
connected = True
try:
tn = telnetlib.Telnet(host)
tn.set_debuglevel(0)
tn.read_until(loginprompt,10)
tn.write(user + "\n")
tn.expect([passwordprompt],10)
tn.write(password + "\n")
loginresponse = tn.expect([prompt,failedlogin])
if loginresponse[0] == 1:
print "Login failed"
connected = False
tn.close()
else:
tn.write("disable clipaging\n")
tn.expect([prompt])
except:
print "Could not connect to switch "+host
connected = False

No telnet allowed.

Here is what I've tried.

getImage = "scp USER@XXXX:summitX-X.X.X-patchX.X.xos summitX-X.X.X-patchX.X.xos"

exsh.clicmd(getImage)

Now the switch starts the download. How do I get the PW propmpt or even give the script a password via an argument?
GTM-P2G8KFN