在python的telnetlib中检测到关闭的连接 [英] Detect a closed connection in python's telnetlib

查看:499
本文介绍了在python的telnetlib中检测到关闭的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python的 telnetlib 连接到远程telnet服务器.我很难检测连接是否仍然打开,或者远程服务器是否关闭了我的连接.

I'm using python's telnetlib to connect to a remote telnet server. I'm having a hard time detecting if the connection is still open, or if the remote server closed it on me.

下一次尝试读取或写入连接时,我会注意到该连接已关闭,但希望有一种方法可以按需检测它.

I will notice the connection is closed the next time I try to read or write to it, but would like to have a way to detect it on demand.

有没有一种方法可以发送某种"Are You There"数据包而不影响实际连接? telnet RFC 支持您在那里"和"NOP"命令-只是不确定如何让telnetlib发送它们!

Is there a way to send some sort of an 'Are You There' packet without affecting the actual connection? The telnet RFC supports an "are you there" and "NOP" commands - just not sure how to get telnetlib to send them!

推荐答案

您应该可以通过这种方式发送NOP:

You should be able to send a NOP this way:

from telnetlib import IAC, NOP

... 

telnet_object.sock.sendall(IAC + NOP)

这篇关于在python的telnetlib中检测到关闭的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆