56 lines
1.2 KiB
Plaintext
56 lines
1.2 KiB
Plaintext
local iwinfo = require 'iwinfo'
|
|
|
|
local counts = { total = 0
|
|
, wifi = 0
|
|
, wifi24 = 0
|
|
, wifi5 = 0
|
|
}
|
|
|
|
local list = io.lines("/sys/kernel/debug/batman_adv/bat0/transtable_local")
|
|
local clients = {}
|
|
for line in list do
|
|
local mac, _, flags, lastseen = line:match("^ %* ([0-9a-f:]+) *(.- )%[(.-)%] +(%d+%.%d+)")
|
|
if mac then
|
|
if not flags:match('P') then
|
|
counts.total = counts.total + 1
|
|
clients[mac:lower()] = true
|
|
|
|
if flags:match('W') then
|
|
counts.wifi = counts.wifi +1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function count_iface_stations(iface)
|
|
local wifitype = iwinfo.type(iface)
|
|
if wifitype == nil then
|
|
return
|
|
end
|
|
|
|
local freq = iwinfo[wifitype].frequency(iface)
|
|
local key
|
|
if freq >= 2400 and freq < 2500 then
|
|
key = "wifi24"
|
|
elseif freq >= 5000 and freq < 6000 then
|
|
key = "wifi5"
|
|
else
|
|
return
|
|
end
|
|
|
|
for k, v in pairs(iwinfo[wifitype].assoclist(iface)) do
|
|
if clients[k:lower()] then
|
|
counts[key] = counts[key] + 1
|
|
end
|
|
end
|
|
end
|
|
|
|
local ifaces = {}
|
|
uci:foreach("wireless", "wifi-iface", function(s)
|
|
if s.network == "client" and s.mode == "ap" then
|
|
count_iface_stations(s.ifname)
|
|
end
|
|
end)
|
|
|
|
return counts
|