I'd like to check if a connection using the telnetlib is still up.
The way I do it is to send a ls
command and check the answer, but I'm sure there must be a smoother solution.
I'd like to check if a connection using the telnetlib is still up.
The way I do it is to send a ls
command and check the answer, but I'm sure there must be a smoother solution.
I've got the idea from here, so kudos to them, the code could be something like this
def check_alive(telnet_object):
try:
if telnet_object.sock:
telnet_object.sock.send(telnetlib.IAC + telnetlib.NOP)
telnet_object.sock.send(telnetlib.IAC + telnetlib.NOP)
telnet_object.sock.send(telnetlib.IAC + telnetlib.NOP)
return True
except:
pass
the idea is pretty simple:
I've used this method for both direct and proxied(SocksiPy) connections against a couple of Cisco routers