I Am Trying To Connect to an ssh server in python using pxssh lib
#!/usr/bin/python
import pxssh
attempt = pxssh.pxssh()
if not attempt.login(IP, USERNAME, PASSWORD):
print("SSH LOGIN FAILED USING USERNAME : " + USERNAME + " AND PASSWORD : " + PASSWORD)
else:
print("LOGIN WAS SUCCESSFUL USING USERNAME : " + USERNAME + " AND PASSWORD : " + PASSWORD)
attempt.sendline("pwd")
attempt.prompt()
print attempt.before
break
it works fine when password is correct and logs into server and executes
pwd
but when password is incorrect or login failes for any reason the program breaks i expect this :
print("SSH LOGIN FAILED USING USERNAME : " + USERNAME + " AND PASSWORD : " + PASSWORD)
but instead i get this error:
File "./ssh.py", line 19, in <module>
if not attempt.login(IP, USERNAME, PASSWORD):
File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 292, in login
raise ExceptionPxssh ('password refused')
pexpect.pxssh.ExceptionPxssh: password refused
Aucun commentaire:
Enregistrer un commentaire