cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2373
Views
5
Helpful
4
Replies

NETMIKO to cisco

Dhikra Marghli
Level 5
Level 5

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

4 Replies 4

Dhikra Marghli
Level 5
Level 5

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

Seb Rupik
VIP Alumni
VIP Alumni

Hi there,

Have your tried:

pip install netmiko 

cheers,

Seb.

 

yes i put this comand in cmd 

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.