【发布时间】:2022-01-21 00:32:30
【问题描述】:
如何在 python 中构建 telnet 服务器?我应该使用什么工具? 我在互联网上看到了很多代码,但没有任何效果。 它需要在没有登录提示的情况下将 python 文件作为 shell 运行。 我该怎么做?
【问题讨论】:
如何在 python 中构建 telnet 服务器?我应该使用什么工具? 我在互联网上看到了很多代码,但没有任何效果。 它需要在没有登录提示的情况下将 python 文件作为 shell 运行。 我该怎么做?
【问题讨论】:
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
【讨论】: