Is there a way to check if a paramiko
SSH connection is still alive?
In [1]: import paramiko
In [2]: ssh = paramiko.SSHClient()
In [3]: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
In [4]: ssh.connect(hostname)
I want to mimic something like this (which doesn't currently exist)
In [5]: ssh.isalive()
True
The python package paramiko was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as safe to use.
Using exec_command() in Paramiko returns a tuple (stdin, stdout, stderr) . Most of the time, you just want to read stdout and ignore stdin and stderr . You can get the output the command by using stdout. read() (returns a string) or stdout.
While you wait for paramiko on Python 3, you can use putty.
if ssh.get_transport() is not None:
ssh.get_transport().is_active()
should do it .... assuming I read the docs right.
I had observed is_active() returning false positives.
I would recommend using this piece:
# use the code below if is_active() returns True
try:
transport = client.get_transport()
transport.send_ignore()
except EOFError, e:
# connection is closed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With