-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask13.py
More file actions
37 lines (26 loc) · 1.04 KB
/
Copy pathtask13.py
File metadata and controls
37 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re
regex = re.compile('(?P<mac>\S+) +(?P<ip>\S+) +\d+ +\S+ +(?P<vlan>\d+) +(?P<port>\S+)')
result = []
with open(r'C:\Users\bodan\PycharmProjects\ProjectsE\train') as data:
for line in data:
match = regex.search(line)
if match:
result.append(match.groupdict())
print('К коммутатору подключено {} устройства'.format(len(result)))
for num, comp in enumerate(result, 1):
print('Параметры устройства {}:'.format(num))
for key in comp:
print('{:10}: {:10}'.format(key,comp[key]))
regex1 = ('Host \S+ '
'in vlan (\d+) '
'is flapping between port '
'(\S+) and port (\S+)')
ports = set()
with open(r'C:\Users\bodan\PycharmProjects\ProjectsE\log') as f:
for line in f:
match = re.search(regex1, line)
if match:
vlan = match.group(1)
ports.add(match.group(2))
ports.add(match.group(3))
print('Петля между портами {} в VLAN {}'.format(', '.join(ports), vlan))