πŸ” FIU AutoSec - Capstone Usage Script

Cisco switch configurations were automated using Python and pyserial to ensure consistent VLAN and voice-ready network layouts within FIU laboratory environments.

Summary of the Capstone Switch and Router Configuration Script

This Python script configures a Cisco switch through the serial console using the pyserial library. It automatically executes the following tasks:

  • Identifies the correct COM or USB serial port
  • Authenticates access to the switch console and applies VLAN, voice, Quality of Service (QoS), and port configurations.Configures the hostname, management IP address, and Message of the Day (MOTD) banner.
  • Saves the running configuration to NVRAM

🧷Auto Port Detection

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.

πŸ“¦End-to-End Setup

Applies hostname, management IP, VLANs, port roles, trunking, MOTD, and finally saves the configurationβ€”ready for a lab demo in one pass.

πŸŽ›οΈVoice & QoS Ready

Voice ports are assigned to VLAN 10 with mls qos trust cos, preparing the switch for VoIP phones and latency-sensitive traffic.

πŸ”Repeatable Labs

Reset and standardize multiple switches quickly for capstone showcases, classroom labs, or repeatable PoCs without retyping CLI commands.

πŸ›‘οΈSecure Defaults

Implements console and VTY protections, local user accounts, and encrypted secrets so devices aren't left with factory-default access.

πŸ“ŠPredictable Layout

Maps ports consistently to VOICE, USERS, SERVERS, and DEV_TEST VLANs with a trunk uplink and unused port shut down for clean lab topologies.

1. Prerequisites and Requirements

1.1 Hardware

1.2 Software

Install pyserial

pip install pyserial

2. Script Structure and Core Modules

The script relies on serial, serial.tools.list_ports, time, and re to automate the CLI over the console line.

Key Imports

import serial import serial.tools.list_ports import time import re

Core Functions

  • 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.

Example: Error Handling Block

if __name__ == "__main__": try: main() except Exception as e: print(f"[ERROR] {e}") input("\nPress Enter to exit...")

3. Network Design Applied by the Script

3.1 Hostname & Management

Management Interface (VLAN 1):

3.2 VLANs

3.3 Port Assignments

3.4 Demo Credentials (Lab Only)

⚠️ Security Notice

These 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.

4. Running the Script

4.1 Connect Everything

4.2 Verify Python & pyserial

python --version pip show pyserial

4.3 Save the Script

Save your Python code as:

configure_switch.py

4.4 Execute from Terminal / Command Prompt

On Windows:

python configure_switch.py

On macOS / Linux (if python points to Python 2):

python3 configure_switch.py

4.5 Expected Output

You should see output similar to:

[βœ“] Using detected port: COM3 [*] Starting FIU Capstone VLAN + Voice configuration... β†’ enable β†’ configure terminal ... ↳ Confirmed [confirm] for: delete flash:vlan.dat ↳ Confirmed copy destination filename ... [βœ“] Configuration completed successfully. Network Summary: β€’ VLAN 10 - Voice (Fa0/1–16) β€’ VLAN 20 - Users (Fa0/17–30) β€’ VLAN 30 - Servers (Fa0/31–38) β€’ VLAN 40 - Dev-Test (Fa0/39–46) β€’ Trunk Port Fa0/47 β†’ UniFi Router β€’ Admin Username: admin / Password: 123456789 β€’ Management IP: 192.168.1.5 / Gateway: 192.168.1.1

4.6 Optional: Verify on the Switch

Connect with PuTTY, Tera Term, or another terminal and run:

show vlan brief show ip interface brief show running-config

5. Customizing the Configuration

Adjust the commands list inside configure_switch() to match your exact FIU lab needs.

5.1 Change Hostname

"hostname SW1",

5.2 Management IP / Gateway

"ip default-gateway 192.168.1.1", "interface vlan1", "ip address 192.168.1.5 255.255.255.0",

5.3 VLANs and Port Ranges

Edit VLAN IDs, names, and interface ranges:

"vlan 20", "name USERS", "exit", "interface range fa0/17 - 30", "switchport access vlan 20",

5.4 Trunk Port and Allowed VLANs

"interface fa0/47", "switchport trunk allowed vlan 1,10,20,30,40",

Best Practice

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.

Back to Top & Overview