Code
#! /usr/bin/env python
import getpass
import sys
import telnetlib
HOST = "10.10.10.11" #the IP address of the switch
user = raw_input("Enter your Telnet username ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST) #establishing telnet session with the defined switch
tn.read_until("Username: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
for n in range (2,10): # create VLANs 2-9
tn.write ("vlan " + str(n) + "\n")
tn.write ("name python_vlan_" + str(n) + "\n")
tn.write ("exit\n")
tn.write ("end\n")
tn.write ("exit\n") #exit the telnet session
print tn.read_all()
Running the script
Only default VLANs can be observed before running the script.
VLANs after running the script.
0 Comments