06-24-2022 01:10 AM - last edited on 05-08-2023 11:32 AM by Paul Zimmerman
Hello
I wantto use language python Netmiko to add some commands to 400 router cisco !!
for me it the first time i use pyhon Netmiko
so
i have switch layer 2 2960 cisco have username admin and password admin123
enbale secret admin123
so i want to add command snmp to 400 switch cisco
so i want to test two switch cisco
so what's the scrpit correct can i add command SNMP to two switch ??
iwait a reply from expert Python
Thanks
06-24-2022 01:32 AM
I try to write exmple
from netmiko import ConnectionHandler
cat2960 ={
"device_type":"cisco_ios",
"ip":"10.20.20.2",
"username":"cisco",
"password":"cisco",
"secret":"sotetel123",
}
net_connect = ConnectHandler(**cat2960)
net_connect.enable()
ouput = net_connect.send_command("show vlan")
print(output)
for vlan in range(10,51,10):
config_commands = ["vlan" +str(vlan),"name Netmiko_vlan"+str(vlan)]
ouput = net_connect.send_config_set_commands
print (ouput)
ouput = net_connect.send_command("show vlan")
print(output)
========>
Traceback (most recent call last):
File "C:/python/Python310/ssh.py", line 1, in <module>
from netmiko import ConnectionHandler
ImportError: cannot import name 'ConnectionHandler' from 'netmiko' (C:\python\Python310\lib\site-packages\netmiko\__init__.py)
how i can resolve this error message !
Thanks
06-24-2022 03:19 AM
Hi there,
Have your tried:
pip install netmiko
cheers,
Seb.
06-24-2022 03:21 AM
yes i put this comand in cmd
06-24-2022 05:28 AM
You had some typos and incorrect syntax, try the following:
from netmiko import ConnectHandler cat2960 = { "device_type":"cisco_ios", "ip":"10.20.20.2", "username ":"cisco", "password":"cisco", "secret":"sotetel123"} net_connect = ConnectHandler(**cat2960) net_connect.enable() output = net_connect.send_command("show vlan") print(output) for vlan in range(10,51,10): config_commands = ["vlan" +str(vlan),"name Netmiko_vlan"+str(vlan)] output = net_connect.send_config_set_commands print (output) output = net_connect.send_command("show vlan") print(output)
cheers,
Seb.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide