|
#!/usr/bin/env python
import subprocess
import telnetlib
import time
import getpass
f = open("list.txt")
line = f.readlines()
username = raw_input("Username:")
password = getpass.getpass("Password: ")
def telnet(username,password,Host):
tn = telnetlib.Telnet(Host,port =23,timeout =10)
# tn.set_debuglevel(2)
tn.read_until('Username:')
tn.write(username + '\n')
tn.read_until('Password:')
tn.write(password + '\n')
print tn.read_until('>')
tn.write('screen-length 0 temporary'+ "\n")
print tn.read_until('>')
tn.write('display aaa route all'+'\n')
print tn.read_until('>')
tn.close()
for Host in line:
Host = Host[0:len(Host)-1] #此处说明读取设备列表后只提取到倒数第一个字符,也就是删除换行符
telnet(username,password,Host)
f.close() |
|
|