python - 瞻博网络防火墙配置文件到字典
问题描述
我在学校做一个项目。我要求将瞻博网络防火墙配置文件转换为另一种防火墙语法。我的问题是将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;"
},
}
}
解决方案
我在工作中遇到了类似的问题,在格式良好的 UI 中显示配置的值并获得最新配置,我使用“显示 xml”格式运行 CLI 命令。例如显示配置安全区域 | 显示xml
这会以漂亮的 xml 格式返回输出,然后可以使用各种 XML 阅读器进行读取。
您还可以使用“显示 json”选项以 json 格式返回输出。
推荐阅读
- data-visualization - 如何在 Apache Superset 中编辑查询?
- puppet - 将符号链接的内容复制到目录
- algorithm - 找到比 O(n^2) 更好的相似名称
- git - 更改 git branch -vv 的格式
- javascript - 如何使用下拉菜单更改背景颜色渐变
- javascript - 如何独立调用 d3.svg.line()?
- mysql - 优化最新时间戳查询mysql
- android - Android使用重力=左调整ImageView的大小
- ffmpeg - 使用 Android NDK r17 构建 C 库 (FFmpeg):未定义对“__mulodi4”的引用
- ajax - 在 Angular 5 中动态地将 routerLink 添加到通过 AJAX 动态创建的组件中