19.07 -> query connected wlan clients

Hi,

I upgraded one of my AccessPoints to 19.07-rc1. The firmware runs nicely - but one thing changed - which is not so nicely - but I think there is no way back :smiley:

On 18.06 I could query my connected clients with this simple shell-script I created:

aps="192.168.1.1 192.168.1.2"

for ap in $aps;
do
        tmpfile=$(mktemp /tmp/getwifi_clients.sh-cookie-$ap.XXXXXX)
        curl -s --cookie-jar $tmpfile -k -d "luci_username=root&luci_password=MYPASS" https://$ap/cgi-bin/luci
        curl -s --cookie $tmpfile -k https://$ap/cgi-bin/luci/admin/network/wireless_assoclist | grep -oE '"bssid":"[[:xdigit:]]{2}(:[[:xdigit:]]{2}){5}"' | grep -oE '[[:xdigit:]]{2}(:[[:xdigit:]]{2}){5}'
        rm -f $tmpfile
done

But in 19.07 the script /cgi-bin/luci/admin/network/wireless_assoclist is not availible.
I have seen, that now the information is gotten from /cgi-bin/luci/admin/ubus

Can someone help to update my script or point me to some docs. The ubus seams to me more complicated than before.

I use this information's for my smarthome as a presence check.

I think you are using a quite convoluted way to obtain that information... Instead of querying the web app and parsing the output, I would try to call "iw" or "ubus" directly.

I don't like to call it with ssh... web would be really simple to connect remotely.... specially I can transfer the code to a python code, which my smarthome project uses.

but I are really close to a solution with the new interface....

EDIT: ok, thats now my code....

cat getwifi_clients.sh
#!/bin/sh

aps="192.168.0.1 192.168.0.2"
test -n "$1" && set -x

for ap in $aps;
do
        tmpfile=$(mktemp /tmp/getwifi_clients.sh-cookie-$ap.XXXXXX)
        curl -s --cookie-jar $tmpfile -k -d "luci_username=root&luci_password=MYPASS" https://$ap/cgi-bin/luci | grep -e "Invalid" -e "Ungültiger" && rm -f $tmpfile && continue
        if [ "$ap" = "192.168.0.2" ]
        then
                curl -s --cookie $tmpfile -k https://$ap/cgi-bin/luci/admin/network/wireless_assoclist | grep -oE '"bssid":"[[:xdigit:]]{2}(:[[:xdigit:]]{2}){5}"' | grep -oE '[[:xdigit:]]{2}(:[[:xdigit:]]{2}){5}'
        else
                sysauth=`grep -oE 'sysauth  [[:alnum:]]{32}' $tmpfile | sed 's/sysauth  //'`
                JSON_STRING=$( jq -c -n \
                                --arg sysauth "$sysauth" \
                                '[ { "jsonrpc": "2.0", "id": 1, "method": "call", "params": [$sysauth,"iwinfo","assoclist",{"device":"wlan2g"}]},
                                   { "jsonrpc": "2.0", "id": 2, "method": "call", "params": [$sysauth,"iwinfo","assoclist",{"device":"wlan5g"}]} ]' )
                curl -s --cookie $tmpfile -H "Content-Type: application/json" -k -d "$JSON_STRING" https://$ap/cgi-bin/luci/admin/ubus | jq -r '.. | objects | .mac // empty'
        fi
        rm -f $tmpfile
done

There is a package called luci-app-commands that allows to execute shell commands through luci. (And prints the ouput of the command)

So you could execute iw (as eduperez suggest) and parse the output?
Maybe that's easier?

2 Likes

I second that. The luci-app-commands package was made exactly for this purpose.

ok, luci-app-commands is not bad at all... but

  1. the command to run is a little to complex, to put it in the command field.. so I have to make a script.
    as an example:
#!/bin/sh
(
  iw dev wlan2g station dump
  iw dev wlan5g station dump
) | grep -oE '[[:xdigit:]]{2}(:[[:xdigit:]]{2}){5}'
  1. the generated link is not the same on multiple devices, so I have to drop my loop and call for every ap a single curl command...
  2. no auth is done...? with auth I also need more code on the calling side...

however... at least my version seams also not so bad at all :slight_smile:

I think about it, maybe I switch to luci-app-commands - I always have it installed - but I use it to trigger wps-pbc command from webinterface (after login).