我在python中有以下脚本,目标是使用telnet lib创建一个python脚本,并将Cisco路由器配置备份到外部文件。但是,每次我运行此脚本时它都会挂起。任何帮助或建议将不胜感激。
import telnetlib
import getpass
import time
import os
ip_add=raw_input('Please enter IP your would like to back up: ')
os.chdir('/Users/user/Backup_configuration/')
uname = raw_input('Please enter username for {} :'.format(ip_add))
print 'Please enter Password for {} :'.format(ip_add)
passwd = getpass.getpass()
connect = telnetlib.Telnet(ip_add)
connect.read_until('Username: ')
connect.write(uname+'\n')
connect.read_until('Password: ')
connect.write(passwd + '\n')
connect.write('config t\n hostname changed1\n end \n terminal len 0\n wr mem\n' )
time.sleep(3)
connect.write('show run\n')
out = connect.read_all()
filen= open('telnet_file.txt', 'w')
filen.write(out)
filen.close()
答案 0 :(得分:0)