![](/img/trans.png)
[英]Using Python: How can I telnet into a server and then from that connection telnet into a second server?
[英]how can I connect through telnet with python?
我在 python 中制作了这个程序,以使用 23 端口连接支持 telnet 的设备,用户:admin 和密码:pass:
import getpass
import telnetlib
HOST = '192.168.1.10'
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"dir\n")
tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))
但是我有这个输出并且程序没有连接:输入您的远程帐户:管理员警告:QtConsole 不支持密码模式,您输入的文本将可见。 经过
我做错了什么? 请帮忙
我没有正确理解您在说什么,但是如果您想使用 cmd 或 powershell 进行连接,那么您可以使用子进程模块,只需导入它,如果您想运行 cmd 命令,则只需键入:
subprocess.run(["dir"])
如果您在 cmd 命令中有一些参数,那么您可以这样做:
subprocess.run(["dir", "-a"]
请记住不要在命令中放置空格,如果您有更多参数,请记住使用列表。
希望它会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.