python 3异步telnet服务器和客户端协议库

telnetlib3的Python项目详细描述


Travis Continuous IntegrationCoveralls Code CoverageLatest VersionDownloadsJoin Chat

简介

telnetlib3是用于python的telnet客户机和服务器库。这个项目 需要python 3.3及更高版本,使用asyncio模块。

快速示例

使用流接口编写telnet服务器,该接口提供基本的战争游戏:

importasyncio,telnetlib3@asyncio.coroutinedefshell(reader,writer):writer.write('\r\nWould you like to play a game? ')inp=yield fromreader.read(1)ifinp:writer.echo(inp)writer.write('\r\nThey say the only way to win ''is to not play at all.\r\n')yield fromwriter.drain()writer.close()loop=asyncio.get_event_loop()coro=telnetlib3.create_server(port=6023,shell=shell)server=loop.run_until_complete(coro)loop.run_until_complete(server.wait_closed())

编写一个telnet客户端,使用此服务器玩战争游戏:

importasyncio,telnetlib3@asyncio.coroutinedefshell(reader,writer):whileTrue:# read stream until '?' mark is foundoutp=yield fromreader.read(1024)ifnotoutp:# End of Filebreakelif'?'inoutp:# reply all questions with 'y'.writer.write('y')# display all server outputprint(outp,flush=True)# EOFprint()loop=asyncio.get_event_loop()coro=telnetlib3.open_connection('localhost',6023,shell=shell)reader,writer=loop.run_until_complete(coro)loop.run_until_complete(writer.protocol.waiter_closed)

命令行

这个包中有两个命令行脚本。

telnetlib3-client

Small terminal telnet client. Some example destinations and options:

telnetlib3-client nethack.alt.org
telnetlib3-client --encoding=cp437 --force-binary blackflag.acid.org
telnetlib3-client htc.zapto.org

telnetlib3-server

Telnet server providing the default debugging shell. This provides a simple shell server that allows introspection of the session’s values, for example:

tel:sh> help
quit, writer, slc, toggle [option|all], reader, proto

tel:sh> writer
<TelnetWriter server mode:kludge +lineflow -xon_any +slc_sim server-will:BINARY,ECHO,SGA client-will:BINARY,NAWS,NEW_ENVIRON,TTYPE>

tel:sh> reader
<TelnetReaderUnicode encoding='utf8' limit=65536 buflen=0 eof=False>

tel:sh> toggle all
wont echo.
wont suppress go-ahead.
wont outbinary.
dont inbinary.
xon-any enabled.
lineflow disabled.

tel:sh> reader
<TelnetReaderUnicode encoding='US-ASCII' limit=65536 buflen=1 eof=False>

tel:sh> writer
<TelnetWriter server mode:local -lineflow +xon_any +slc_sim client-will:NAWS,NEW_ENVIRON,TTYPE>

两个命令行脚本都接受参数--shell=my_module.fn_shell 描述到签名协程的python模块路径 shell(reader, writer),正如上面的例子。

功能

执行以下RFC规范:

  • rfc-727,“telnet注销选项”,1977年4月。
  • rfc-779,“telnet发送位置选项”,1981年4月。
  • rfc-854,“telnet协议规范”,1983年5月。
  • rfc-855,“telnet选项规范”,1983年5月。
  • rfc-856,“telnet二进制传输”,1983年5月。
  • rfc-857,“telnet echo选项”,1983年5月。
  • rfc-858,“telnet抑制继续选项”,1983年5月。
  • rfc-859,“telnet状态选项”,1983年5月。
  • rfc-860,“telnet定时标记选项”,1983年5月。
  • rfc-885,“telnet记录结束选项”,1983年12月。
  • rfc-1073,“telnet窗口大小选项”,1988年10月。
  • rfc-1079,“telnet终端速度选项”,1988年12月。
  • rfc-1091,“telnet终端类型选项”,1989年2月。
  • rfc-1096,“telnet x显示位置选项”,1989年3月。
  • rfc-1123,“对因特网主机的要求”,1989年10月。
  • rfc-1184,“telnet linemode选项(扩展选项)”,1990年10月。
  • rfc-1372,“telnet远程流量控制选项”,1992年10月。
  • rfc-1408,“telnet环境选项”,1993年1月。
  • rfc-1571,“telnet环境选项互操作性问题”,1994年1月。
  • rfc-1572,“telnet环境选项”,1994年1月。
  • rfc-2066,“telnet字符集选项”,1997年1月。

进一步阅读

更多文档可在https://telnetlib3.readthedocs.org/

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java如何添加排除某个数字的随机生成器?   在Eclipse中将所有包集中在一个包中(对于Java项目)   java在部署我的应用程序后无法连接到MySQL   Ntier应用程序中的java NoClassDefFoundException   java泛型类型转换?   使用buildr编译期间的java jar插件   java查找排序数组中重复值的计数   运行Spring Boot cmdline的java示例给出了“找不到run()方法”`   java为什么不调用windowClosed?   java jsch身份验证在没有私钥的情况下失败   java如何在我的jtable中获得100多行?   java在遗留Android Studio项目中创建测试文件夹   java 安卓。所容纳之物res.Resources$NotFoundException:资源ID#0x7f080087   java Eclipse自动格式化变量初始化