-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRIP.py
More file actions
49 lines (40 loc) · 1.58 KB
/
Copy pathRIP.py
File metadata and controls
49 lines (40 loc) · 1.58 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
38
39
40
41
42
43
44
45
46
47
48
49
from netmiko import ConnectHandler
from getpass import getpass
router_num = int(input("How many routers would you like to configure: "))
while router_num > 0:
hostip = input('Router IP: ')
USER = input('SSH Username: ')
PASS = getpass('SSH Password: ') # Securely handle password input
Router = {
'device_type': 'cisco_ios',
'ip': hostip,
'username': USER,
'password': PASS
}
try:
myssh = ConnectHandler(**Router)
# Improved command to get hostname correctly
hostname_output = myssh.send_command('show run | include hostname')
if hostname_output:
device_name = hostname_output.split()[-1]
else:
device_name = "Unknown Router"
# Configure RIP
print(f"Configuring RIP on {device_name}...")
rip_commands = [
'router rip',
'version 2',
'no auto-summary'
]
network_num = int(input("How many networks would you like to enable in RIP: "))
for _ in range(network_num):
network_i = input('Please specify the network to enable (e.g., 192.168.1.0): ')
rip_commands.append(f'network {network_i}')
output = myssh.send_config_set(rip_commands)
print(f"RIP configuration output for {device_name}:\n{output}")
print(f'RIP configured successfully on {device_name}')
print('-' * 79)
except Exception as e:
print(f"Failed to configure {hostip}: {str(e)}")
router_num -= 1
input("Press ENTER to finish")