首页 > 解决方案 > 瞻博网络防火墙配置文件到字典

问题描述

我在学校做一个项目。我要求将瞻博网络防火墙配置文件转换为另一种防火墙语法。我的问题是将juniper conf文件转换为字典,以便我可以处理它

我尝试用“{”和“}”和一堆不同的东西分割文本,但似乎没有帮助

    family inet {
        replace:
        /*
        ** $Id:$
        ** $Date:$
        ** $Revision:$
        **
        */
        filter bridge {
            interface-specific;
            term rule100 {
                from {
                    source-address {
                        10.0.0.1/32;
                    }
                    destination-address {
                        10.0.0.1/32;
                    }
                    protocol tcp;
                    destination-port 80;
                }
                then {
                    discard;
                }
            }
      }
    }
}

我期待这样的python字典

dic = { "term rule100" : {
                "from" :{
                    "source-address" : "10.0.0.1/32;",
                    "destination-address" : "10.0.0.1/32;",
                    "protocol" :"tcp;", "destination-port" : "80;",
                    "then" : "discard;"
                },
            }
}

标签: pythonjuniper

解决方案


我在工作中遇到了类似的问题,在格式良好的 UI 中显示配置的值并获得最新配置,我使用“显示 xml”格式运行 CLI 命令。例如显示配置安全区域 | 显示xml

这会以漂亮的 xml 格式返回输出,然后可以使用各种 XML 阅读器进行读取。

您还可以使用“显示 json”选项以 json 格式返回输出。


推荐阅读