Package: tplinkrouterc6u
TP-Link Router APIPython package for API access and management for TP-Link RouterSeeSupported routersInstallationpip install tplinkrouterc6u && pip install -r requirements.txtDependenciesrequestspycryptodomeUsageEnter the host & credentials used to log in to your router management page. Username is admin by default. But you may pass username as third parameterfromtplinkrouterc6uimportTplinkRouterProvider,TplinkC1200Router,WififromloggingimportLoggerrouter=TplinkRouterProvider.get_client('http://192.168.0.1','password')# You may use client directly like# router = TplinkRouter('http://192.168.0.1', 'password')# You may also pass username if it is different and a logger to log errors as# router = TplinkRouter('http://192.168.0.1','password','admin2', Logger('test'))# If you have the TP-link C1200 V2 or similar, you can use the TplinkC1200Router class instead of the TplinkRouter class.# Remember that the password for this router is different, here you need to use the web encrypted password.# To get web encrypted password, read Web Encrypted Password section# router = TplinkC1200Router('http://192.168.0.1','WebEncryptedPassword', Logger('test'))try:ifrouter.authorize():# authorizing# Get firmware info - returns Firmwarefirmware=router.get_firmware()# Get status info - returns Statusstatus=router.get_status()ifnotstatus.guest_2g_enable:# check if guest 2.4G wifi is disablerouter.set_wifi(Wifi.WIFI_GUEST_2G,True)# turn on guest 2.4G wifi# Get Address reservations, sort by ipaddrreservations=router.get_ipv4_reservations()reservations.sort(key=lambdaa:a.ipaddr)forresinreservations:print(f"{res.macaddr}{res.ipaddr:16s}{res.hostname:36}{'Permanent':12}")# Get DHCP leases, sort by ipaddrleases=router.get_ipv4_dhcp_leases()leases.sort(key=lambdaa:a.ipaddr)forleaseinleases:print(f"{lease.macaddr}{lease.ipaddr:16s}{lease.hostname:36}{lease.lease_time:12}")finally:router.logout()# always logout as TP-Link Web Interface only supports upto 1 user loggedThe TP-Link Web Interface only supports upto 1 user logged in at a time (for security reasons, apparently).
So before action you need to authorize and after logoutWeb Encrypted PasswordIf you got exception -You need to use web encrypted password instead. Check the documentation!or you have TP-link C1200 V2 or similar router you need to get web encrypted password by these actions:Go to the login page of your router. (default: 192.168.0.1).Type in the password you use to login into the password field.Click somewhere else on the page so that the password field is not selected anymore.Open the JavaScript console of your browser (usually by pressing F12 and then clicking on "Console").Typedocument.getElementById("login-password").value;Copy the returned value as password and use it.FunctionsFunctionArgsDescriptionReturnget_firmwareGets firmware info about the routerFirmwareget_statusGets status about the router info including wifi statuses and wifi clients infoStatusget_ipv4_statusGets WAN and LAN IPv4 status info, gateway, DNS, netmaskIPv4Statusget_ipv4_reservationsGets IPv4 reserved addresses (static)[IPv4Reservation]get_ipv4_dhcp_leasesGets IPv4 addresses assigned via DHCP[IPv4DHCPLease]set_wifiwifi:Wifi, enable: boolAllow to turn on/of 4 wifi networkssend_smsphone_number: str, message: strSend sms for LTE routersrebootreboot routerauthorizeauthorize for actionslogoutlogout after all is doneDataclassFirmwareFieldDescriptionTypehardware_versionReturns like - Archer C6UstrmodelReturns like - Archer C6U v1.0strfirmware_versionReturns like - 1.1.3 Build 3425243strStatusFieldDescriptionTypewan_macaddrrouter wan mac addressstr, Nonewan_macaddressrouter wan mac addressmacaddress.EUI48, Nonelan_macaddrrouter lan mac addressstrlan_macaddressrouter lan mac addressmacaddress.EUI48wan_ipv4_addrrouter wan ipv4 addressstr, Nonewan_ipv4_addressrouter wan ipv4 addressipaddress.IPv4Address, Nonelan_ipv4_addrrouter lan ipv4 addressstr, Nonelan_ipv4_addressrouter lan ipv4 addressipaddress.IPv4Address, Nonewan_ipv4_gatewayrouter wan ipv4 gatewaystr, Nonewan_ipv4_gateway_addressrouter wan ipv4 gateway addressipaddress.IPv4Address, Nonewired_totalTotal amount of wired clientsintwifi_clients_totalTotal amount of main wifi clientsintguest_clients_totalTotal amount of guest wifi clientsintclients_totalTotal amount of all connected clientsintguest_2g_enableIs guest wifi 2.4G enabledboolguest_5g_enableIs guest wifi 5G enabledbool, Noneiot_2g_enableIs IoT wifi 2.4G enabledbool, Noneiot_5g_enableIs IoT wifi 5G enabledbool, Nonewifi_2g_enableIs main wifi 2.4G enabledboolwifi_5g_enableIs main wifi 5G enabledbool, Nonewan_ipv4_uptimeInternet Uptimeint, Nonemem_usageMemory usagefloat, Nonecpu_usageCPU usagefloat, NonedevicesList of all wifi clientslist[Device]DeviceFieldDescriptionTypetypeclient connection type (2.4G or 5G, guest wifi or main wifi)Wifimacaddrclient mac addressstrmacaddressclient mac addressmacaddressipaddrclient ip addressstripaddressclient ip addressipaddresshostnameclient hostnamestrpackets_senttotal packets sentint, Nonepackets_receivedtotal packets receivedint, NoneIPv4ReservationFieldDescriptionTypemacaddrclient mac addressstrmacaddressclient mac addressmacaddressipaddrclient ip addressstripaddressclient ip addressipaddresshostnameclient hostnamestrenabledenabledboolIPv4DHCPLeaseFieldDescriptionTypemacaddrclient mac addressstrmacaddressclient mac addressmacaddressipaddrclient ip addressstripaddressclient ip addressipaddresshostnameclient hostnamestrlease_timeip address lease timestrIPv4StatusFieldDescriptionTypewan_macaddrrouter mac addressstrwan_macaddressrouter mac addressmacaddresswan_ipv4_ipaddrrouter mac addressstrwan_ipv4_ipaddressrouter mac addressipaddresswan_ipv4_gatewayrouter WAN gateway IP addressstrwan_ipv4_gateway_addressrouter WAN gateway IP addressipaddresswan_ipv4_conntyperouter connection typestrwan_ipv4_netmaskrouter WAN gateway IP netmaskstrwan_ipv4_netmask_addressrouter WAN gateway IP netmaskipaddresswan_ipv4_pridnsrouter primary dns serverstrwan_ipv4_pridns_addressrouter primary dns serveripaddresswan_ipv4_snddnsrouter secondary dns serverstrwan_ipv4_snddns_addressrouter secondary dns serveripaddresslan_macaddrrouter mac addressstrlan_macaddressrouter mac addressmacaddresslan_ipv4_ipaddrrouter LAN IP addressstrlan_ipv4_ipaddressrouter LAN IP addressipaddresslan_ipv4_dhcp_enablerouter LAN DHCP enabledboollan_ipv4_netmaskrouter LAN gateway IP netmaskstrlan_ipv4_netmask_addressrouter LAN gateway IP netmaskipaddressremoterouter remotebool, NoneEnumWifiWifi.WIFI_2G - main wifi 2.4GWifi.WIFI_5G - main wifi 5GWifi.WIFI_GUEST_2G - guest wifi 2.4GWifi.WIFI_GUEST_5G - guest wifi 5GWifi.WIFI_IOT_2G - IoT wifi 2.4GWifi.WIFI_IOT_5G - IoT wifi 5GSupported routersFully tested Hardware VersionsArcher A7 V5Archer AX10 v1.0Archer AX20 v1.0Archer AX21 v1.20Archer AX50 v1.0Archer AX55 V1.60Archer AX72 V1Archer AX73 V1Archer AX3000 V1Archer AX6000 V1Archer AX11000 V1Archer C1200 v2.0 (You need to useweb encrypted password)Archer C6 v2.0Archer C6 v3.0Archer C6U v1.0Archer C7 v5.0Archer MR200 v5Archer MR200 v5.3Archer MR600TL-WA3001 v1.0TL-MR6400 v5Not fully tested Hardware VersionsAD7200 V2Archer A6 (V2 and V3)Archer A9 V6Archer A10 (V1 and V2)Archer A20 (V1, V3)Archer C7 V4Archer C8 (V3 and V4)Archer C9 (V4 and V5)Archer C59 V2Archer C90 V6Archer C900 V1Archer C1200 V3Archer C1900 V2Archer C2300 (V1, V2)Archer C4000 (V2 and V3)Archer C5400 V2Archer C5400X V1TD-W9960 v1TL-WR1043N V5Please let me know if you have tested integration with one of this or other model. Open an issue with info about router's model, hardware and firmware versions.Adding Support For More ModelsGuidelinesCONTRIBUTING.mdLocal DevelopmentDownload this repository.Runpip install -e path/to/repo.Make changes to files within thetplinkrouter6udirectory.Exercise the changes following the "Usage" section above.The sanity check test.py illustrates a few tests and runs through a list of queries in queries.txt creating logs of the results of each query in the logs folder. This can be used to capture the dictionary output of all cgi-bin form submissions.Thanks ToEncryptionWrapper for TP-Link Archer C6Uby@Singleton-95Encryption for TP-Link W9960by@Electry