【发布时间】:2019-05-04 00:52:37
【问题描述】:
我正在通过 python 脚本远程登录到 cisco 交换机。代码如下:
#!/usr/bin/python
import getpass
import sys
import telnetlib
HOST = "10.203.4.1"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("vt100\n")
tn.write("ls\n")
tn.write("exit\n")
print tn.read_all()
它只是在运行脚本后挂断。我该如何解决这个问题?
【问题讨论】:
-
也许 Cisco 写
Username:或Login:但您的代码正在等待login:。使用print在屏幕上为您写下更多信息 - 例如“现在我将等待'登录:'”等。