2025-02-12 17:36:12 +01:00
|
|
|
#!/bin/env python3
|
|
|
|
|
2025-02-14 21:11:21 +01:00
|
|
|
def parse_ip(block):
|
|
|
|
result = {}
|
|
|
|
current_interface = ""
|
|
|
|
for line in block.splitlines():
|
|
|
|
if not line.startswith("\t"):
|
|
|
|
current_interface= line.split(":")[0]
|
|
|
|
result[current_interface] = []
|
|
|
|
elif line.strip().startswith("inet"):
|
|
|
|
result[current_interface].append(line.strip().split(" ")[1])
|
|
|
|
return result
|
|
|
|
|
2025-02-12 17:36:12 +01:00
|
|
|
def parse_freebsd(content):
|
|
|
|
current_section = ""
|
|
|
|
result = {}
|
|
|
|
for line in content.splitlines():
|
|
|
|
if line.startswith("#####") and line.endswith("#####"):
|
|
|
|
current_section = line.replace(" ","").replace("#","").lower()
|
|
|
|
result[current_section] = ""
|
|
|
|
else:
|
|
|
|
if current_section:
|
2025-02-14 21:11:21 +01:00
|
|
|
result[current_section] += line + "\n"
|
2025-02-12 17:36:12 +01:00
|
|
|
from pprint import pprint
|
|
|
|
#pprint(result)
|
2025-02-14 21:11:21 +01:00
|
|
|
result["ip"] = parse_ip(result["interfaces"])
|
|
|
|
return result
|
2025-02-12 17:36:12 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|
|
|