AlexandrErohin / TP-Link-Archer-C6U

Python package for API access and management for TP-Link Routers. See supported routers list
GNU General Public License v3.0
43 stars 14 forks source link

Tp-link c1200 v2 doesn't return wireless clients in AP mode #12

Closed swwgames closed 7 months ago

swwgames commented 7 months ago

Added an if statement which checks if there are any devices connected, if that is not the case it checks admin/wireless?form=statistics for connected devices. I did this because when the C1200 v2 router runs in access point mode, the normal check doesn't return connected devices connected wirelessly. I know this is the case for my router the C1200 V2, maybe this will also relate to others. The downside is that this api call only returns mac addresses, and type of connection. So no Hostname and ip address. right now is set the ip to 0.0.0.0 and the hostname to UKNOWN. I don't now if this is the best configuration. the code:

        if not status.devices:
            device_data = self.request('admin/wireless?form=statistics&operation=read')
            for item in device_data:
                type = Wifi.WIFI_2G if '2.4GHz' == item['type'] else Wifi.WIFI_5G
                status.devices.append(Device(type, macaddress.EUI48(item['mac']), ipaddress.IPv4Address('0.0.0.0'),
                                         'UNKOWN'))
AlexandrErohin commented 7 months ago

Hi! Could you show the admin/status?form=all&operation=read response when router in AP mode. Please mask passwords and mac addresses before posting And could you also show the response from admin/wireless?form=statistics&operation=read

swwgames commented 7 months ago

admin/status?form=all&operation=read

{
    "success": true,
    "data": {
        "wireless_2g_wep_format3": "hex",
        "wireless_5g_disabled": "off",
        "wireless_5g_wep_type2": "64",
        "storage_available_unit": "B",
        "storage_vendor": "",
        "usb_storages": {},
        "storage_available": 0,
        "printer_count": 0,
        "printer_name": "None",
        "wan_ipv4_netmask": "255.255.255.0",
        "storage_capacity": 0,
        "access_devices_wired": [
            {
                "wire_type": "wired",
                "macaddr": "macaddrr",
                "ipaddr": "192.168.1.228",
                "hostname": "SERVER"
            },
            {
                "wire_type": "wired",
                "macaddr": "macaddr",
                "ipaddr": "192.168.1.254",
                "hostname": "UNKNOWN"
            },
            {
                "wire_type": "wired",
                "macaddr": "macaddr",
                "ipaddr": "192.168.1.187",
                "hostname": "LAPTOP"
            }
        ],
        "wireless_2g_wds_status": "disable",
        "wireless_2g_wep_type3": "64",
        "wireless_2g_wep_format2": "hex",
        "wan_ipv6_conntype": "none",
        "mem_usage": 0.43,
        "access_devices_wireless_host": [
            {
                "wire_type": "2.4G",
                "macaddr": "macaddr",
                "ipaddr": "192.168.1.186",
                "hostname": "UNKNOWN"
            }
        ],
        "guest_5g_psk_key": "",
        "cpu_usage": 0.28,
        "guest_2g_encryption": "none",
        "wireless_5g_encryption": "psk",
        "guest_5g_ssid": "TP-Link_Guest_21CC_5G",
        "guest_5g_hidden": "off",
        "guest_access": "off",
        "wireless_2g_txpower": "high",
        "guest_5g_enable": "off",
        "wireless_2g_macaddr": "macaddr",
        "wireless_5g_disabled_all": "off",
        "guest_5g_extinfo": {
            "support_wds_show": "no",
            "support_band": "both"
        },
        "wireless_5g_current_channel": "48",
        "wireless_2g_port": "1812",
        "wireless_2g_wpa_cipher": "auto",
        "wireless_5g_wep_key4": "",
        "wireless_2g_htmode": "40",
        "guest_5g_encryption": "none",
        "wireless_2g_wep_key3": "",
        "wireless_5g_psk_cipher": "auto",
        "guest_2g_psk_cipher": "aes",
        "wireless_5g_wep_format1": "hex",
        "wireless_2g_wep_select": "1",
        "wireless_2g_wep_type2": "64",
        "wireless_5g_wep_select": "1",
        "wireless_2g_psk_key": "password",
        "wireless_2g_wep_type1": "64",
        "wireless_5g_ssid": "ssid_5Ghz",
        "wireless_2g_wep_key1": "",
        "wireless_2g_current_channel": "1",
        "wan_ipv4_snddns": "8.8.8.8",
        "wan_ipv6_ip6addr": "::",
        "wireless_5g_extinfo": {
            "support_wds_show": "no",
            "support_band": "both"
        },
        "guest_2g_hidden": "off",
        "wireless_2g_channel": "1",
        "wireless_2g_enable": "on",
        "wireless_2g_extinfo": {
            "support_wds_show": "no",
            "support_band": "both"
        },
        "wireless_2g_wpa_version": "auto",
        "wireless_5g_psk_key": "password",
        "wireless_2g_wep_format4": "hex",
        "lan_ipv4_netmask": "255.255.255.0",
        "wireless_5g_wep_key2": "",
        "wireless_5g_enable": "on",
        "wireless_5g_wep_type1": "64",
        "wireless_5g_wep_key1": "",
        "lan_macaddr": "macaddr",
        "wireless_2g_encryption": "psk",
        "wireless_2g_psk_cipher": "auto",
        "wireless_5g_port": "1812",
        "guest_2g_psk_version": "rsn",
        "wireless_5g_wpa_cipher": "auto",
        "guest_5g_disabled": "off",
        "wireless_5g_hwmode": "anac_5",
        "wan_ipv6_gateway": "::",
        "lan_ipv6_link_local_addr": "FE80::1E3B:F3FF:FE30:21CC/64",
        "wireless_5g_wep_type4": "64",
        "wireless_5g_wep_format4": "hex",
        "wan_ipv6_snddns": "::",
        "wireless_2g_disabled": "off",
        "wireless_5g_wep_format3": "hex",
        "wan_ipv6_pridns": "::",
        "wireless_2g_hidden": "off",
        "wireless_2g_psk_version": "auto",
        "guest_isolate": "off",
        "wan_macaddr": "macaddr",
        "wireless_5g_wps_state": "configured",
        "wireless_2g_wps_state": "configured",
        "wireless_5g_hidden": "off",
        "wireless_5g_psk_version": "auto",
        "wireless_5g_wep_format2": "hex",
        "wireless_2g_ssid": "ssid_2.4Ghz",
        "wireless_2g_wep_key4": "",
        "wireless_5g_wep_mode": "auto",
        "wan_ipv4_ipaddr": "192.168.1.100",
        "guest_2g_extinfo": {
            "support_wds_show": "no",
            "support_band": "both"
        },
        "lan_ipv6_assign_type": "slaac",
        "wireless_2g_wep_format1": "hex",
        "wireless_2g_wep_key2": "",
        "lan_ipv6_ipaddr": "FE80::1E3B:F3FF:FE30:21CC/64",
        "wireless_2g_server": "",
        "wireless_5g_htmode": "80",
        "guest_5g_psk_cipher": "aes",
        "guest_2g_disabled": "off",
        "wan_ipv4_gateway": "192.168.1.254",
        "wireless_2g_disabled_all": "off",
        "guest_2g_psk_key": "",
        "wireless_5g_wpa_key": "",
        "guest_5g_psk_version": "rsn",
        "guest_2g_ssid": "TP-Link_Guest_21CC",
        "wireless_2g_wpa_key": "",
        "wireless_5g_server": "",
        "wireless_5g_macaddr": "macaddr",
        "lan_ipv4_dhcp_enable": "Off",
        "wireless_5g_txpower": "high",
        "wireless_2g_wep_type4": "64",
        "wireless_2g_hwmode": "bgn",
        "wireless_5g_channel": "48",
        "wan_ipv6_enable": "on",
        "wan_ipv4_pridns": "192.168.1.254",
        "guest_2g_enable": "off",
        "wireless_5g_wep_key3": "",
        "wireless_2g_wep_mode": "auto",
        "wireless_5g_wpa_version": "auto",
        "wireless_5g_wep_type3": "64",
        "storage_capacity_unit": "B",
        "wan_ipv4_conntype": "static",
        "lan_ipv4_ipaddr": "192.168.1.100",
        "wireless_5g_wds_status": "disable"
    }
}

admin/wireless?form=statistics&operation=read

  {
      "data": [
          {
              "mac": "macaddr",
              "type": "2.4GHz",
              "encryption": "wpa/wpa2-psk",
              "rxpkts": 4867482,
              "txpkts": 450333
          },
          {
              "mac": "macaddr",
              "type": "2.4GHz",
              "encryption": "wpa/wpa2-psk",
              "rxpkts": 2953078,
              "txpkts": 134815
          },
          {
              "mac": "macaddr",
              "type": "2.4GHz",
              "encryption": "wpa/wpa2-psk",
              "rxpkts": 2055255,
              "txpkts": 405532
          },
          {
              "mac": "macaddr",
              "type": "2.4GHz",
              "encryption": "wpa/wpa2-psk",
              "rxpkts": 2039162,
              "txpkts": 35192
          },
          {
              "mac": "macaddr",
              "type": "2.4GHz",
              "encryption": "wpa/wpa2-psk",
              "rxpkts": 2663232,
              "txpkts": 818347
          },
          {
              "mac": "macaddr",
              "type": "2.4GHz",
              "encryption": "wpa/wpa2-psk",
              "rxpkts": 2001167,
              "txpkts": 79104
          }
      ],
      "timeout": false,
      "success": true,
      "operator": "load"
  }

As you can see the form=all method only responds with one device, the form=statistics responds with all the devices connected at this moment. I hope this helps, if you have any questions feel free to ask them.

AlexandrErohin commented 7 months ago

As access_devices_wireless_host returns one result - this changes will not work as status.devices would have one device Could you show also admin/wireless?form=all&operation=read ? And is there any parameter from admin/status?form=all&operation=read response which shows AP mode is enable/disable ?

swwgames commented 7 months ago

I added a check for the router mode. if the router is in ap mode it checks if the mac address is already found, if not is will be added but without the ip address and hostname.

AlexandrErohin commented 7 months ago

@swwgames Could you resolve conflicts?

swwgames commented 7 months ago

I am trying but i don't know what the problem is

swwgames commented 7 months ago

I fixed it

AlexandrErohin commented 7 months ago

Thank you! I have merged and added packets_sent and packets_received to Device Could you test please device list?

swwgames commented 7 months ago

Yes, that works!