Python backup Cisco IOS device brief example

Source: Internet
Author: User
Tags get ip

The Netmik library is used for Ssh,os libraries to manage folders, and datetime is used to generate file names
.

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 () i    F folder_name in Folder_v:print ("There are a same name file already, please input again!") Else:create_path = path + folder_name os.mkdir (create_path) print ("Created folder:" +folder_name+ "su  ccessfully!\n ") Print (" Note:the bakup file'll be is in: ", Create_path) breakfor IP in ip_addr:cisco[' IP '] = Ip.strip (' \ n ') print (' Connecting: ' +ip.strip ("\ n") + "...") Net_connect = Connecthandler (**cisco) print ("Connect    Ed successfully! ") Net_connect.enable () Run_config = Net_connect.send_command (' show run ') Save_name = Ip.strip () + datetime.datetime.no W (). Strftime ("-%y%m%d-%h_%m_%s") print (' Backing Up: ' +ip.strip ("\ n") + ' ... ') f = open (Create_path + "\ \" +save_name+ ". T XT ", ' 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 !

Python backup Cisco IOS device brief example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.