-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetmiko_prompt_global_config.py
More file actions
31 lines (25 loc) · 1.07 KB
/
netmiko_prompt_global_config.py
File metadata and controls
31 lines (25 loc) · 1.07 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
from netmiko import ConnectHandler
cisco_device = {
'device_type': 'cisco_ios', #device type from https://github.com/ktbyers/netmiko/blob/master/netmiko/ssh_dispatcher.py
'host': '10.1.1.1',
'username': 'admin',
'password': 'admin',
'port': 22, # optional, default 22
'secret': 'cisco', # this is the enable password
'verbose': True # optional, default False
}
connection = ConnectHandler(**cisco_device)
# getting the router's prompt
prompt = connection.find_prompt()
if '>' in prompt:
connection.enable() # entering the enable mode
output = connection.send_command('sh run')
print(output)
if not connection.check_config_mode(): # returns True if it's already in the global config mode
connection.config_mode() # entering the global config mode
print(connection.check_config_mode())
connection.send_command('username u3 secret cisco')
connection.exit_config_mode() # exiting the global config mode
print(connection.check_config_mode())
print('Closing connection')
connection.disconnect()