如何在python中构建telnet服务器?我该用什么工具?我在互联网上见过很多代码,但都没有用。它需要在没有登录提示的情况下作为shell运行python文件。我怎么能这么做?
发布于 2021-12-18 14:12:24
telnetlib模块提供了实现Telnet协议的Telnet类。
一个简单的例子说明了典型的用法:
import getpass
import telnetlib
HOST = "localhost"
user = input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(b"ls\n")
tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))
更多详情:
https://docs.python.org/3/library/telnetlib.html
若要安装库,请键入以下命令:
pip install telnetlib3
发布于 2022-06-10 12:24:42
https://stackoverflow.com/questions/70404067
复制相似问题