亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Python 備份cisco ios 設備 簡例

標簽:
Python

netmik库用来ssh,os库用来管理文件夹,datetime用于生成文件名
.

from netmiko import ConnectHandlerimport osimport datetime#define device typecisco = {    'device_type':'cisco_ios',    'ip':'',    'username':'admin',    'password':'ccie',    'secret':'ccie',}

.

#get ip address from a fileip_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)        breakfor 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 instructf.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 !

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消