Created
June 5, 2020 17:49
-
-
Save whoo/968ce1ae32070632243fb46a85e12ec4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
config = {} | |
with open('fortigate.cfg') as fh: | |
for line in fh: | |
args = line.split() | |
action = args.pop(0) | |
# python3: action, *args = line.split() | |
if action == 'config': | |
header = ' '.join(args) | |
if header not in config: | |
config[header] = {} | |
if action == 'edit': | |
section = ' '.join(args).strip('"') | |
if section not in config[header]: | |
config[header][section] = {} | |
if action == 'set': | |
name = args.pop(0) | |
value = ' '.join(args).strip('"') | |
config[header][section][name] = value | |
print(json.dumps(config)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment