【网络自动化】批量提取华为防火墙的指定策略

使用python检索所有华为防火墙配置文件的rule,并提取需要的rule到txt文本中
示例:
security-policy
rule name trust_test1
source-zone trust
destination-zone untrust
source-address x.x.x.x mask 255.255.255.0
destination-address address-set test1
service protocol tcp source-port 0 to 65535 destination-port 2222 3333
action permit
rule name trust_test2
source-zone trust
destination-zone untrust
source-address x.x.x.x mask 255.255.255.0
destination-address address-set test2
service protocol tcp source-port 0 to 65535 destination-port 2222 3333
action permit

防火墙配置文件中几万个,其中包含rule test1、test2
要求:提取所有rule中包含test2地址集的rule
在该程序的目录下,新建一个 “FW配置文件” 文件夹存放防火墙配置文件
执行程序后在当前目录下生成FW_rule.txt文件
在这里插入图片描述
在这里插入图片描述
python代码如下

#-*- coding:utf-8 -*-
# Author:Sheng Luhao
# ScriptName:  configuration_get_all_sec_ruleV1.1.py
# Create Date: 2020-12-2 ‏‎20:05
#***************************************************************#
import os
import re
import sys

if __name__ == '__main__':
    find_info = input('输入需要搜索的内容:')
    file_list_all = os.scandir('FW配置文件')  # 遍历FW文件
    file_list = []
    for item in file_list_all
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值