A Python SDK and Cisco IOS-style CLI for TP-Link managed switches. Configure VLANs, QoS, port mirroring, storm control, and more from Python or an interactive shell — no browser, no REST API, no SSH required.
New project — limited hardware coverage
Developed and tested against a single TL-SG108E (hardware v6.0, firmware 1.0.0 Build 20230218 Rel.50633). Compatibility with other TP-Link managed switch models and firmware versions is untested. The API and CLI command set may change without notice. Verify each operation on your hardware before use in production.
TP-Link managed switches have no REST API, no SSH, and no serial console — their only configuration interface is a frameset-based web UI on port 80. tplink-tool reverse-engineers that web interface to expose a clean Python SDK and an interactive CLI that feels like a Cisco IOS shell.
The SDK reads state by fetching .htm
pages and parsing JavaScript variable declarations embedded in the first
<script> block. Configuration
writes are plain HTTP GET or POST requests — a quirk of the firmware
confirmed by capturing browser devtools traffic.
Session management, automatic re-authentication on session expiry, and transparent recovery from mode-change-induced web server restarts are handled internally so calling code never has to think about them.
One file, one dependency (requests).
Drop tplink_switch.py into your
project and import.
Full read coverage
System info, IP settings, port state and statistics, port mirroring, LAG/trunk groups, IGMP snooping, loop prevention, MTU VLAN, port-based VLAN, 802.1Q VLAN with PVIDs, QoS mode and priorities, bandwidth control, storm control, cable diagnostics.
Full write coverage
Everything you can do in the web UI, including config backup and restore, factory reset, reboot, and password change.
Transparent session management
Automatic re-authentication before the 10-minute cookie expires. Transparent recovery when mode-change operations (e.g. enabling 802.1Q) restart the switch's web server mid-session.
A modal shell modelled after Cisco IOS. Commands can be abbreviated to
their shortest unambiguous prefix. The no
prefix and do prefix (run exec commands
from config sub-modes) work as expected.
| Mode | Selected commands |
|---|---|
| Exec | show version / interfaces / vlan / qos / port-mirror, clear counters, test cable-diagnostics, copy running-config, reload, write erase |
| Config | hostname, ip address, [no] spanning-tree, [no] igmp snooping, qos mode, monitor session, mtu-vlan, vlan, port-vlan, username |
| Interface | [no] shutdown, speed, [no] flowcontrol, switchport access/trunk/pvid, [no] channel-group, qos port-priority, bandwidth ingress/egress, storm-control |
Cable diagnostics (TDR) — firmware bug
The TDR diagnostic CGI handler drops the TCP connection without returning any data on firmware 1.0.0 Build 20230218. All cable diagnostic results return NotTested on this firmware. The SDK implementation is correct — the bug is in the firmware. If TDR works on your firmware version, please open an issue.
Single hardware revision tested
Only the TL-SG108E v6.0 has been tested. Earlier hardware revisions and other TP-Link managed switch models likely share the same protocol but have not been verified.