31 lines
935 B
Python
31 lines
935 B
Python
#!/bin/env python3
|
|
|
|
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
|
|
|
|
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:
|
|
result[current_section] += line + "\n"
|
|
from pprint import pprint
|
|
#pprint(result)
|
|
result["ip"] = parse_ip(result["interfaces"])
|
|
return result
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|