Python 备份cisco ios 设备 简例
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python 备份cisco ios 设备 简例,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1522字,纯文字阅读大概需要3分钟。
内容图文
![Python 备份cisco ios 设备 简例](/upload/InfoBanner/zyjiaocheng/1048/faa2337810204fcf8924ee7cdbf67de9.jpg)
.
from netmiko import ConnectHandler
import os
import datetime
#define device type
cisco = {
‘device_type‘:‘cisco_ios‘,
‘ip‘:‘‘,
‘username‘:‘admin‘,
‘password‘:‘ccie‘,
‘secret‘:‘ccie‘,
}
.
#get ip address from a file
ip_addr = open("G:\\PythonProject_netmiko\\ipList.txt")
path ="G:\\PythonProject_netmiko\\"
folder_v = os.listdir() #查看當前文件夾所有文件
while True:
print("input your bak file folder name:")
folder_name = input()
if folder_name in folder_v:
print("there is a same name file already, please input again!")
else:
create_path = path + folder_name
os.mkdir(create_path)
print("Created folder:"+folder_name+" successfully!\n")
print("NOTE:the bakup file will be in: ",create_path)
break
for ip in ip_addr:
cisco[‘ip‘] = ip.strip(‘\n‘)
print(‘Connecting: ‘+ip.strip("\n")+"...")
net_connect = ConnectHandler(**cisco)
print("Connected successfully !")
net_connect.enable()
run_config = net_connect.send_command(‘show run‘)
save_name = ip.strip() + datetime.datetime.now().strftime("-%Y%m%d-%H_%M_%S")
print(‘Backing up: ‘+ip.strip("\n")+‘...‘)
f = open(create_path +"\\"+save_name+".txt",‘w‘)
f.write(run_config)
f.close()
print("Backed up successfully!")
f = open(create_path +"\\0_IP-date-time.fileType",‘w‘)#used to instruct
f.close()
ip_addr.close()
.
For minding codes
print("\n\n\nBacked up all devices compeleted ! ")
print("Please check the bakeup file in the follow folder: "+create_path)
.
Over~ Good luck to you !
原文:http://blog.51cto.com/jackor/2068351
内容总结
以上是互联网集市为您收集整理的Python 备份cisco ios 设备 简例全部内容,希望文章能够帮你解决Python 备份cisco ios 设备 简例所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。