温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用python脚本利用SSH协议通过TFTP备份批量备份山石防火墙配置

发布时间:2020-07-04 20:07:50 来源:网络 阅读:2068 作者:NetworkTiler 栏目:网络管理

    

    #!/usr/bin/python

    #-*- coding: utf-8 -*-

    import re

    import paramiko          #引入ssh模块,该模块需要单独安装。

    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 !!'


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI