#!/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