Answer the question
In order to leave comments, you need to log in
Why paramiko incorrectly detects ssh connection status?
Here is the function to check if the username/password is correct:
def SSHCheck(target, SSHport, user, password):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
resultCode = 0
try:
ssh.connect(target, port = SSHport, username = user, password = password, timeout=5, banner_timeout = 5, auth_timeout=5)
except paramiko.AuthenticationException:
resultCode = 1
except socket.error:
resultCode = 2
except paramiko.ssh_exception.SSHException:
resultCode = 3
finally:
ssh.close()
return resultCode
def SSHCheck(target, SSHport, user, password):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
resultCode = 0
try:
ssh.connect(target, port = SSHport, username = user, password = password, timeout=5, banner_timeout = 5, auth_timeout=5)
except paramiko.AuthenticationException:
resultCode = 1
except socket.error:
resultCode = 2
except paramiko.ssh_exception.SSHException:
resultCode = 3
else:
channel = ssh.get_transport().open_session()
channel.get_pty()
channel.settimeout(5)
channel.exec_command('ls')
print(channel.recv(1024)) #Выводим результат команды
channel.close()
finally:
ssh.close()
return resultCode
b"\r\r\nEntering character mode\r\r\nEscape character is '^]'.\r\r\n\r\r\n\r\n\rlogin as: -c\r\n\ rpassword: **"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question