使用 python telnet - 输入密码后没有提示

问题描述 投票:0回答:1

我正在尝试通过 python 脚本远程登录到 NETGEAR SWITCH, 我成功通过 Putty 连接,但是当我尝试使用 python 代码时 输入密码后我什么也没得到(没有提示)(密码是空的,只需要按回车键即可。

这是代码:

    import getpass
import telnetlib
import time

HOST = "10.10.10.1"
user = input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until(b"User: ")
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'))

我尝试设置睡眠延迟并仔细检查 read_until 参数以及是否有空格,但没有成功,

请帮忙。

python telnet
1个回答
0
投票

使用 tn.expect 而不是 tn.read_until

© www.soinside.com 2019 - 2024. All rights reserved.