defis_alive(self): """Returns a boolean flag with the state of the connection.""" null = chr(0) if self.remote_conn isNone: log.error("Connection is not initialised, is_alive returns False") returnFalse if self.protocol == "telnet": ... else: # SSH try: # Try sending ASCII null byte to maintain the connection alive log.debug("Sending the NULL byte") # 向 channel 发送一个空字符串,如果能正常发送成功,则说明会话还在 # 网络设备的超时时间是按照最后一次接收到命令的时间开始算的 # 所以每次进行 is_alive() 的判断,都会刷新 vty 的超时时间 self.write_channel(null) return self.remote_conn.transport.is_active() except (socket.error, EOFError): log.error("Unable to send", exc_info=True) # If unable to send, we can tell for sure that the connection is unusable returnFalse returnFalse