python 行编辑 telnet 服务器
我正在用 python 创建一个服务器(它所做的事情无关紧要),但我希望它接受 telnet 连接并提供具有行编辑功能(tabcompletion、emacs/vi-mode 等)和每个会话历史记录的命令行界面。我已成功创建 telnet 会话、禁用线路模式并启用服务器回显。
我最初的想法是使用 readline,但 python readline 模块似乎只适用于 stdin 上的单个会话;并检查底层的 readline 库,这似乎是它的工作方式。
然而,我想做的是为每个客户端创建一个实例(如果您愿意,可以将其称为状态),并在收到字符(字节)时将其馈送到状态。一旦生成了完整的行,它就会将其传递给可以解析它的服务器。
所以我的问题是是否有一个库可以处理这种事情,甚至一个 c 库就足够了。
编辑:澄清一下,我已经有了一个功能齐全的服务器,但我希望将 telnet 接口作为附加组件来重新配置、获取信息等。
I am creating a server in python (what it is doing is irrelevant), but I would like it to accept telnet connections and provide a command line interface with line editing capabilities (tabcompletion, emacs/vi-mode, etc) and history per session. I have successfully created the telnet session, disabled line mode and enabled server echo.
My initial thoughts were using readline but the python readline module seems to only work for a single session on stdin; and examining the underlying readline library that seems to be the way it works.
What I would like to do however is to create an instance (call it state if you like) for each client, and as characters (bytes) are received feed to the state. Once a complete line has been generated it would pass it to the server which may parse it.
So my question is if there is a library which handles this kind of thing, even a c-library would be sufficient.
EDIT: To clarify, I've got a fully functional server already, but I want the telnet interface as an add on to reconfigure, get information, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您已经对 TELNET 部分进行了排序,现在您想要提供 BASH、KSH 等 shell 中常见的功能。我自己没有尝试过,但看看 shython:“具有 bash 和 python 功能的多功能 shell”。
It sounds like you've got the TELNET part sorted, and now you want to provide features commonly found in shells like BASH, KSH etc. I've not tried it myself, but have a look as shython: "a versatile shell having features of both bash and python".
也许
cmd
库可能感兴趣/有帮助?Perhaps the
cmd
library could be of interest/help?您需要 telnetlib http://docs.python.org/library /telnetlib.html?highlight=telnet#module-telnetlib
You need telnetlib http://docs.python.org/library/telnetlib.html?highlight=telnet#module-telnetlib