我通过python脚本telnet到cisco交换机。代码如下:使用python的Telnet 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()
它只是在运行脚本后挂起。我该如何解决这个问题?
也许思科写'用户名:'或'登录:'但是你的代码正在等待'登录:'。使用'print'在屏幕上写更多信息给你 - 比如“现在我将等待”登录:'“等。 – furas