Python – Script4: Configure Vlans on Multiple Switches

Configure Vlans 2-9 on devices 192.168.10.21 – 192.168.10.24 & Save configs

import getpass
import sys
import telnetlib
 
user = raw_input(“Enter your telnet username: “)
password = getpass.getpass()
 
for j in range (21,25):
              print “Telnet to host 192.168.10.” + str(j)
              HOST = “192.168.10.” + str(j)
              tn = telnetlib.Telnet(HOST)
 
              tn.read_until(“Username: “)
              tn.write(user + “\n”)
              if password:
                  tn.read_until(“Password: “)
                  tn.write(password + “\n”)
 
              tn.write(“enable\n”)
              tn.write(“cisco\n”)
              tn.write(“conf t\n”)
 
              for n in range(2,10):
                  tn.write(“Vlan ” + str(n) + “\n”)
                  tn.write(“name Python_VLAN_” + str(n) + “\n”)
 
              tn.write(“end\n”)
              tn.write(“wr\n”)
              tn.write(“exit\n”)
 
              print tn.read_all()

Network Architect | CCIEx3 #29824 JNCIE #2197 VCIX-NV

Leave a Comment