mansingh_stack
mansingh_stack

Reputation: 79

netmiko : enable a cisco device

I need to execute command on ios device(3750-switch) in enable mode

given: IP, username, password, protocol is telnet, enable password module: netmiko

challenge: login to device -> enable enable mode -> execute command I need help with syntax for triggering the enable mode on the device enable password is put against secret.

The function to trigger enable mode is device.enable() but i might be wrong.

from netmiko import ConnectHandler

cisco_3x={
   'device_type': 'cisco_ios_telnet',
   'ip': 'address',
   'username': 'xxx',
   'password': 'xxx',
   'secret': 'xxx',
    }
mansingh=ConnectHandler(**cisco_3x)
mansingh.enable()
output=mansingh.send_command("show running")
print output

Upvotes: 2

Views: 10818

Answers (3)

Shervin Hariri
Shervin Hariri

Reputation: 105

You can try with this code :

from netmiko import ConnectHandler


cisco_Router = {
    "device_type": "cisco_ios",
    "host": "router01",
    "username": "your_username",
    "password": "your_password"}

with ConnectHandler(**cisco_Router) as net_connect:

    net_connect.enable()
    result = net_connect.send_command('do show running')
    net_connect.disconnect()

print(result)

Upvotes: 2

this is the correct way!!! on the other hand David Bombal supossed that you have a level15 user configured on the switch.

you can check the console promtp after enable with this command

print(mansingh.find_prompt())

Upvotes: 1

aboyum
aboyum

Reputation: 53

If you have level 15 access to the switch you don't need the enable password.

You give level 15 like this: username user1 privilege 15 secret goodpassword

David Bombal have a couple of examples on configuring switches here: https://github.com/davidbombal/pythonvideos/blob/master/netmiko2.py

for devices in all_devices:

net_connect = ConnectHandler(**devices)
for n in range (2,21):
   print "Creating VLAN " + str(n)
   config_commands = ['vlan ' + str(n), 'name Python_VLAN ' + str(n)]
   output = net_connect.send_config_set(config_commands)
   print output 

Upvotes: 1

Related Questions