Код: Выделить всё
confparse = CiscoConfParse("ipv6_ints.txt")
# extract the interface name and description
# first, we get all interface commands from the configuration
interface_cmds = confparse.find_objects(r"^interface ")
# iterate over the resulting IOSCfgLine objects
for interface_cmd in interface_cmds:
# get the interface name (remove the interface command from the configuration line)
intf_name = interface_cmd.text[len("interface "):]
result["interfaces"][intf_name] = {}
IPv6_REGEX = (r"ipv6\saddress\s(\S+)")
for cmd in interface_cmd.re_search_children(IPv6_REGEX):
ipv6_addr = interface_cmd.re_match_iter_typed(IPv6_REGEX, result_type=IPv6Obj)
result["interfaces"][intf_name].update({
"ipv6": {
"ipv6 address": ipv6_addr.compressed,
}
})
print("\nEXTRACTED PARAMETERS\n")
print(json.dumps(result, indent=4))
Входной файл
Подробнее здесь: https://stackoverflow.com/questions/525 ... -interface