-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit_username_sendto_file.py
43 lines (39 loc) · 1.32 KB
/
audit_username_sendto_file.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
import re
from netmiko import ConnectHandler
devices = ['192.168.0.121', '192.168.0.122', '192.168.0.123']
passwd = input('Key in password: ')
with open('audit.text', 'w') as f:
for ip in devices:
cisco_device = {
'device_type': 'cisco_ios',
'host': ip,
'username': 'bigg',
'password': passwd,
'port': 22,
'secret': 'bigg',
'verbose': True
}
connection = ConnectHandler(**cisco_device)
# print('connecting to ' + ip)
# print('entering enable mode ..')
connection.enable()
# with open('audit.text', 'w') as f:
shrun = connection.send_command('show run')
# print(shrun)
shrun = shrun.splitlines()
# print(shrun)
shrun_idx = [i for i, item in enumerate(shrun) if re.search('^username', item)]
for item in shrun_idx:
print('audit item for router ' + ip + ' : ' + shrun[item] + '\n')
f.write('audit item for router ' + ip + ' : ' + shrun[item] + '\n')
# with open('shrun.txt') as f:
# shrun = f.readlines()
#
# print(shrun)
#
# shrun_idx = [i for i, item in enumerate(shrun) if re.search('^username', item)]
# print(shrun_idx)
# print(type(shrun_idx))
#
# for item in shrun_idx:
# print('audit item: ' + shrun[item])