如何使用Python的telnetlib模块?

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

常用接口:

1、telnetlib.Telnet

2、write()

3、read_until(match)

4、close()

实例应用:

1、连接服务器

importtelnetlib
Host="a.b.c.d"
tn=telnetlib.Telnet(Host,port=23,timeout=10)
tn.set_debuglevel(0)

2、输入登录用户名

tn.read_until(b'login:')
tn.write(b"zte"+b'\n')