Код: Выделить всё
access-list office extended permit tcp host 1.1.1.1 host 2.2.2.2
access-list home extended permit object-group PROTOS4 host 4.4.4.4 host 5.5.5.5
Код: Выделить всё
acl_general_structure = (
r'access-list\s+(?P
[A-Za-z0-9\-\_]+)\s+extended\s+(?Ppermit|deny)'
r'\s'
r'(?P[a-zA-Z0-9]+|(?:object-group\s[A-Za-z\d]+))'
r'\s'
r'host\s(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3})'
r'\s'
r'host\s(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3})'
)
f_in_name="xx.config"
f_out_name=f_in_name + ".csv"
with open(f_in_name, "r", encoding="utf8") as f:
for line in f.readlines():
result=re.match(acl_general_structure,line)
if result:
print(result.groupdict())
Код: Выделить всё
{'policy_name': 'office', 'action': 'permit', 'protocol': 'tcp', 'source': '1.1.1.1', 'destination': '2.2.2.2'}
{'policy_name': 'home', 'action': 'permit', 'protocol': 'object-group PROTOS4', 'source': '4.4.4.4', 'destination': '5.5.5.5'}
Код: Выделить всё
{'policy_name': 'office', 'action': 'permit', 'protocol': 'tcp', 'source': '1.1.1.1', 'destination': '2.2.2.2'}
{'policy_name': 'home', 'action': 'permit', 'protocol': 'PROTOS4', 'source': '4.4.4.4', 'destination': '5.5.5.5'}
Подробнее здесь: https://stackoverflow.com/questions/772 ... ring-group