Home > other >  Pexpect connection SSH actual failure, but return success
Pexpect connection SSH actual failure, but return success

Time:12-30

SSH actual pexpect connection failure, but returns success

Connection:
Wangyy @ kali: ~ $1024/dsa/SSH [email protected] - I/home/wangyy f91e7f1f68b392e33488c5f3a33136/dsa/1024/86-13382 - o PasswordAuthentication=no
SSH: connect to host 192.168.187.129 port 22: Connection refused
Wangyy @ kali: ~/dsa/1024 $

Code:
Try:
Perm_denied='Permission denied'
Ssh_newkey='Are you sure you want to continue'
Conn_closed='Connection closed by remote host'
Conn_refused='SSH: connect to host 192.168.187.129 port 22: Connection refused'
Opt='-o PasswordAuthentication=no'
ConnStr='SSH' + user + + host '@' + '-i' + keyfile + opt
The child=pexpect. Spawn (connStr)
Ret=child. Expect ([pexpect. A TIMEOUT, perm_denied, ssh_newkey, conn_closed, conn_refused, '$',' # '])
If ret==2:
Print (' Adding the host to knownhosts')
Child. Sendline (' yes')
The connect (user, host, keyfile, False)
Elif ret==3:
Print (' connection closed by remote host ')
Fails +=1
Elif ret==4:
Print (" connection refused by remote host ')
Elif ret & gt; 4:
Print (child. Before)
Print (" Success "+ STR (keyfile))
Stop=True

Running, every time go ret> 4, the debug ret has a value of $. Then decide for the login successful,

But in fact the login is failed,
  • Related