我需要在启用模式下在ios设备(3750-交换机)上执行命令
给定: IP、用户名、密码,协议为telnet,使能密码模块: netmiko
挑战:登录到设备->使能模式-> execute命令我需要有关在设备上触发使能模式的语法方面的帮助启用密码是用来保护密码的。
触发启用模式的函数是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发布于 2020-08-05 17:15:58
如果您对交换机具有15级访问权限,则不需要启用密码。
您可以这样设置级别15 : username user1 privilege 15 secret goodpassword
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 发布于 2020-08-18 13:00:43
这才是正确的方式!另一方面,David Bombal假定您在交换机上配置了level15用户。
您可以使用以下命令在启用后查看控制台提示
print(mansingh.find_prompt())发布于 2022-01-12 08:31:58
您可以尝试使用以下代码:
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)https://stackoverflow.com/questions/49759897
复制相似问题