Python SDK and CLI for TP-Link managed switches
Project description
tplink-tool
A Python SDK and interactive CLI for TP-Link managed switches — no browser required.
These switches have no REST API, no SSH, and no serial console. This project reverse-engineers the HTTP web UI shared by many TP-Link managed switch models to provide a clean Python interface and a Cisco IOS-inspired shell.
Developed and tested on:
- Hardware: TL-SG108E v6.0
- Firmware: 1.0.0 Build 20230218 Rel.50633
A full test suite passes against this hardware. Other TP-Link managed switches that share the same web UI are likely compatible.
Files
| File | Purpose |
|---|---|
tplink_switch.py |
Python SDK (Switch class, all read/write operations) |
cli.py |
Interactive CLI (Cisco IOS-style) |
docs/sdk.md |
SDK programmer reference |
docs/cli.md |
CLI user guide |
Requirements
pip install requests
No other dependencies.
Quick start — SDK
from tplink_switch import Switch, PortSpeed
with Switch('192.168.0.1', password='admin') as sw:
# Read system info
print(sw.get_system_info())
# Port status
for port in sw.get_port_settings():
print(port)
# Configure a port
sw.set_port(1, speed=PortSpeed.AUTO, flow_control=False)
# 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)
See docs/sdk.md for the full API reference.
Quick start — CLI
python3 cli.py 192.168.0.1
TL-SG108E# show interfaces
TL-SG108E# configure terminal
TL-SG108E(config)# vlan 10
TL-SG108E(config-vlan-10)# name servers
TL-SG108E(config-vlan-10)# exit
TL-SG108E(config)# interface port 1
TL-SG108E(config-if-gi1)# switchport access vlan 10
TL-SG108E(config-if-gi1)# exit
TL-SG108E(config)# end
TL-SG108E# show vlan
Commands can be abbreviated to their shortest unambiguous prefix (conf t,
sh int, sw acc vl 10, etc.).
See docs/cli.md for the full command reference.
What is supported
Read operations
- System info (firmware, MAC, IP)
- IP settings
- LED state
- Port settings (speed, duplex, flow control, trunk membership)
- Port statistics (TX/RX packet counters)
- Port mirroring
- Port trunking / LAG
- IGMP snooping
- Loop prevention
- MTU VLAN
- Port-based VLAN
- 802.1Q VLAN (membership, PVIDs)
- QoS (mode, per-port priority)
- Bandwidth control (ingress/egress rate limiting)
- Storm control
- Cable diagnostics (TDR) — see firmware note below
Write operations
Everything listed above, plus:
- Config backup and restore
- Factory reset
- Reboot
- Password change
Known firmware issues
Cable diagnostics (TDR) — TL-SG108E v6.0, firmware 1.0.0 Build 20230218 Rel.50633
The run_cable_diagnostic() method is implemented and the status codes
are correct per the firmware's own JavaScript:
| Code | Meaning |
|---|---|
| 0 | NoCable |
| 1 | Normal |
| 2 | Open (unterminated) |
| 3 | Short |
| 4 | OpenShort |
| 5 | CrossCable |
| -1 | NotTested |
However, on the tested firmware the cable_diag_get.cgi POST handler
silently drops the TCP connection before sending any HTTP response. The
GET endpoint returns cached state, which is initialized to -1 (NotTested)
and never changes because the write side is non-functional.
All diagnostic results therefore return NotTested on this firmware.
The code is correct and ready; the limitation is a firmware bug. If
you test on a different firmware version and TDR works, please open an
issue.
Protocol notes
The switch uses a frameset-based HTTP UI on port 80.
- Reads:
GET /<Page>.htm— state is embedded as JavaScript variable declarations in the first<script>block. - Writes:
GET /<name>.cgi?param=value— all configuration writes are GET requests with query-string parameters (not POST). - Session: cookie-based (
H_P_SSID, TTL 600 s). The SDK re-authenticates transparently before expiry and after mode-change operations that restart the switch's web server.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tplink_tool-0.1.0.tar.gz.
File metadata
- Download URL: tplink_tool-0.1.0.tar.gz
- Upload date:
- Size: 79.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3fd8c4a2895b932ee6cac74965759465f505aa9bb25c7d19ceb6793e073bc35
|
|
| MD5 |
aa0d99e059496c7344a1f5afd122315a
|
|
| BLAKE2b-256 |
fb86effa28d81f5d6368dc967dc9a3a13b09cc13b098ba49e2ad6d3cd2d5d768
|
File details
Details for the file tplink_tool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tplink_tool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 41.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21da6c159f8b73ca901894f8b979b8d99d03dee0fadca80b560a0c5526d148ab
|
|
| MD5 |
78ba5abb9b6fcb4c52bf22766bb68ba6
|
|
| BLAKE2b-256 |
96e73c1592007e9dc54eb36a7f85e5abbaf1e3ade75d379bc05d5d4452276405
|