【问题标题】:netmiko : enable a cisco devicenetmiko : 启用 cisco 设备
【发布时间】:2018-09-20 10:38:03
【问题描述】:

我需要在启用模式下在 ios 设备(3750-switch)上执行命令

给定:IP,用户名,密码,协议是telnet,启用密码 模块:netmiko

挑战:登录设备 -> 启用启用模式 -> 执行命令 我需要有关在设备上触发启用模式的语法帮助 启用密码是针对机密的。

触发启用模式的函数是 device.enable() 但我可能错了。

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

【问题讨论】:

  • 是的,这是正确的做法。

标签: python networking


【解决方案1】:

如果您对交换机有 15 级访问权限,则不需要启用密码。

你给 15 级是这样的: 用户名 user1 权限 15 秘密密码

David Bombal 在此处提供了几个配置开关的示例: https://github.com/davidbombal/pythonvideos/blob/master/netmiko2.py

对于 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 

【讨论】:

    【解决方案2】:

    这是正确的方法!!! 另一方面,David Bombal 假设您在交换机上配置了 15 级用户。

    您可以使用此命令启用后检查控制台promtp

    print(mansingh.find_prompt())
    

    【讨论】:

      【解决方案3】:

      你可以试试这段代码:

      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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-05-08
        • 1970-01-01
        • 2022-10-15
        • 2020-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多