-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciscoPhones.py
72 lines (57 loc) · 2.19 KB
/
ciscoPhones.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /usr/bin/python3
import csv, re
csv_headers = [
'Enterprise ID', ' Group ID', ' Device Name',
' Device Type', ' UCount', ' Line Ports',
' New DName', ' New DType', ' User Agent'
]
def cisco():
cnt = 0
phone_models = [
'504',
'112',
'3102'
]
ND_types = [
'Cisco SPA 5XX',
'Cisco-SPA-112',
'Linksys SPA-3102'
]
nw_device_type = {
'504': ND_types[0],
'112': ND_types[1],
'3102': ND_types[2]
}
with open('<YOUR CSV FILE HERE>', 'r') as csv_file:
contents = csv.DictReader(csv_file)
with open('<YOUR CSV FILE HERE>', 'a', newline='') as matched_file:
csv_writer = csv.DictWriter(matched_file, fieldnames=csv_headers, delimiter=',')
# csv_writer.writeheader()
for line in contents:
for model in phone_models:
pattern = re.compile(rf"SPA{model}")
matches = pattern.finditer(str(pattern))
for match in matches:
if match.group(0) in line[' User Agent']:
line[' New DName'] = line[' Device Name']
line[' New DType'] = nw_device_type[model]
csv_writer.writerow(line)
cnt += 1
return cnt
def counter():
cnt = 0
true_false = None
pattern = re.compile(r"(\d{3}|\d{4}|VOIP)-UA")
with open('<YOUR CSV FILE HERE>') as count_entry:
csv_counter = csv.DictReader(count_entry)
for line in csv_counter:
matches = pattern.finditer(line[' User Agent'])
for match in matches:
if match.group(0) in line[' User Agent']:
true_false = True
print(line[' User Agent'])
cnt += 1
else:
true_false = False
print(true_false)
return cnt