Cisco switch configurations were automated using Python and pyserial
to ensure consistent VLAN and voice-ready network layouts within FIU laboratory environments.
This Python script configures a Cisco switch through the serial console using the pyserial library. It automatically executes the following tasks:
Uses serial.tools.list_ports to locate the correct USB/serial COM port, so
you don't have to manually guess between COM3, COM4, or
/dev/ttyUSB0.
Applies hostname, management IP, VLANs, port roles, trunking, MOTD, and finally saves the configurationβready for a lab demo in one pass.
Voice ports are assigned to VLAN 10 with mls qos trust cos, preparing the
switch for VoIP phones and latency-sensitive traffic.
Reset and standardize multiple switches quickly for capstone showcases, classroom labs, or repeatable PoCs without retyping CLI commands.
Implements console and VTY protections, local user accounts, and encrypted secrets so devices aren't left with factory-default access.
Maps ports consistently to VOICE, USERS, SERVERS, and DEV_TEST VLANs with a trunk uplink and unused port shut down for clean lab topologies.
Switch> or Switch#)pyserial library installedpyserial
The script relies on serial, serial.tools.list_ports,
time, and re to automate the CLI over the console line.
detect_com_port(): Finds the first USB/serial adapter and prints
[β] Using detected port: COM3 (or similar).
send_and_confirm(ser, cmd, delay=0.4): Sends a command, waits
for output, automatically presses Enter for [confirm] prompts and copy
destination questions, and logs what was sent.
configure_switch(port): Opens the serial port, runs all
configuration commands (VLANs, ports, QoS, trunk, MOTD), then saves the configuration.
main(): Calls detect_com_port(), runs
configure_switch(), and wraps everything in a try/except with a friendly
[ERROR] message and a "Press Enter to exit..." prompt.
SW1Management Interface (VLAN 1):
VLAN 1192.168.1.5255.255.255.0192.168.1.1VOICEUSERSSERVERSDEV_TESTFa0/1β16 β VLAN 10 (VOICE) + voice VLAN + QoS trustFa0/17β30 β VLAN 20 (USERS)Fa0/31β38 β VLAN 30 (SERVERS)Fa0/39β46 β VLAN 40 (DEV_TEST)Fa0/47 β Trunk to UniFi router (VLANs 1,10,20,30,40)Fa0/48 β Disabled (UNUSED_PORT)123456789username admin privilege 15 secret 123456789
123456789123456789These credentials are for lab and demonstration purposes only. Always change usernames, passwords, and secrets before using this script on any real network. Never commit real credentials or private keys to version control.
pyserialSave your Python code as:
On Windows:
On macOS / Linux (if python points to Python 2):
You should see output similar to:
Connect with PuTTY, Tera Term, or another terminal and run:
Adjust the commands list inside configure_switch() to match your
exact FIU lab needs.
Edit VLAN IDs, names, and interface ranges:
After any change to the commands list, re-run the script on a test switch first,
then verify with show running-config before using it in class demos.