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