← Ordo Artificum

tplink-tool

TP-Link managed switch SDK & CLI

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.

Early development — use with caution github.com/jfrancis42/tplink-tool

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.

What it is

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.

Python SDK

One file, one dependency (requests). Drop tplink_switch.py into your project and import.

from tplink_switch import Switch, PortSpeed
with Switch('192.168.0.1', password='admin') as sw:
    # Read
    info = sw.get_system_info()
    for port in sw.get_port_settings():
        print(port)
    # Configure 802.1Q VLANs
    sw.set_dot1q_enabled(True)
    sw.add_dot1q_vlan(10, name='servers',
        tagged_ports=[8], untagged_ports=[1])
    sw.set_pvid([1], 10)
    # Rate limiting
    sw.set_bandwidth_control([3],
        ingress_kbps=1024, egress_kbps=512)

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.

Interactive CLI

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.

$ python3 cli.py 192.168.0.1 --password admin
switch# show interfaces
switch# configure terminal
switch(config)# vlan 10
switch(config-vlan-10)# name servers
switch(config-vlan-10)# exit
switch(config)# interface port 1
switch(config-if-gi1)# switchport access vlan 10
switch(config-if-gi1)# bandwidth ingress 1024
switch(config-if-gi1)# storm-control broadcast rate 5
switch(config-if-gi1)# exit
switch(config)# end
switch# show vlan
switch# copy running-config backup.bin
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

Known limitations

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.

Requirements

pip install requests
# Python 3.8+, tested on Linux
# Tested: TL-SG108E v6.0, firmware 1.0.0 Build 20230218 Rel.50633