Use the Python script to back up the Huawei switch configuration via TFTP using the SSH protocol

Source: Internet
Author: User
Tags python script

Prerequisite work

Python is not installed by default in the SSH module, SSH features rely on the Paramiko module implementation, the need for their own installation, specific installation steps Baidu itself.

Primary script, as before, configured via TFTP backup

#!/usr/bin/python

#-*-Coding:utf-8-*-

Import re

Import Paramiko #引入ssh模块, the module needs to be installed separately.

Import time

LogTime = Time.strftime ('%y-%m-%d_%h-%m-%s ')

TFTP = raw_input (' Please Enter TFTP Sever IP: ')

temp = open (' Config.txt ', ' W ')

hostname = ' 192.168.202.254 '

Port = 22

Username = ' Admin '

Password = ' Passw0rd '

Client = Paramiko. Sshclient ()

Client.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())

Client.connect (hostname, port, username, password, timeout=5)

Remote_conn = Client.invoke_shell ()

Remote_conn.send (' Display version\n ')

Time.sleep (1)

Remote_conn.send (' \ n ')

out = REMOTE_CONN.RECV (temp)

DeviceName = (Re.findall (str (".*< (. *) >.*"), out)) [0]

Save = "Save%s-%s.cfg"% (devicename,logtime)

Remote_conn.send (save+ ' \ n ')

Time.sleep (1)

Remote_conn.send (' y ' + ' \ n ')

Time.sleep (2)

TFTP_CLI = "tftp%s put%s-%s.cfg"% (tftp,devicename,logtime)

Remote_conn.send (tftp_cli+ ' \ n ')

Time.sleep (2)

Print hostname, ' Backup Success! '


This article is from the "Ah Jian" blog, please be sure to keep this source http://hardwork.blog.51cto.com/2529098/1944534

Use the Python script to back up the Huawei switch configuration via TFTP using the SSH protocol

Related Article

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.