Use the SSH protocol with a python script to back up a bulk backup of a rock firewall configuration via TFTP

Source: Internet
Author: User
Tags python script

#!/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: ')

Import hillstone_icmp

Action = raw_input ("" Please Select Action:

1:config & Backup;

2:backup;

Put Your Choose: ")

For line in open ("Hs_ip_true.txt"):

hostname = line.replace (' \ n ', ')

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

Port = 22

Username = ' 666666 '

Password = ' 666666 '

if action = = ' 2 ':

Try

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 (' show version \ n ')

Time.sleep (2)

Remote_conn.send (' \ n ')

out = REMOTE_CONN.RECV (temp)

Time.sleep (2)

DeviceName = (Re.findall ('. * (? =#) ', out)) [0]

TFTP_CLI = "Export configuration startup to TFTP server%s%s-%s. CFG "% (tftp,devicename,logtime)

Remote_conn.send (tftp_cli+ ' \ n ')

Time.sleep (2)

Print hostname, ' Backup Success! '

Except:

Print hostname, ' Backup Failed! '


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

Use the SSH protocol with a python script to back up a bulk backup of a rock firewall configuration via TFTP

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.