Netmiko SSH Script to Cisco 3750 Switch

Open your favorite editor and copy pasta:
from netmiko import ConnectHandler
c3750 = {
'device_type': 'cisco_ios',
'ip': '10.0.10.24',
'username': 'lab',
'password': 'lab'
}
net_connect = ConnectHandler(**c3750)
output = net_connect.send_command('show ip int brief')
print (output)
config_commands = ['int loop 0', 'ip address 1.1.1.1 255.255.255.0']
output = net_connect.send_config_set(config_commands)
print (output)
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)
Save the file as config.py and execute the script:
python config.py

If we check on our switch we can see that our script has created new vlans.

Leave a Reply