Python – Script2: Configure Vlans on Switch

import getpass
import sys
import telnetlib
 
HOST = raw_input(“Enter Device IP: “)
user = raw_input(“Enter your telnet username:”)
password = getpass.getpass()
 
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”)
tn.write(“vlan 2\n”)
tn.write(“name Python_Vlan_2\n”)
tn.write(“exit\n”)
tn.write(“vlan 3\n”)
tn.write(“name Python_Vlan_3\n”)
tn.write(“exit\n”)
tn.write(“vlan 4\n”)
tn.write(“name Python_Vlan_4\n”)
tn.write(“exit\n”)
tn.write(“vlan 5\n”)
tn.write(“name Python_Vlan_5\n”)
tn.write(“exit\n”)
tn.write(“vlan 6\n”)
tn.write(“name Python_Vlan_6\n”)
tn.write(“exit\n”)
tn.write(“end\n”)
tn.write(“exit\n”)
 
print tn.read_all()

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

Leave a Comment