clients 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local iwinfo = require 'iwinfo'
  2. local counts = { total = 0
  3. , wifi = 0
  4. , wifi24 = 0
  5. , wifi5 = 0
  6. }
  7. local list = io.lines("/sys/kernel/debug/batman_adv/bat0/transtable_local")
  8. local clients = {}
  9. for line in list do
  10. local mac, _, flags, lastseen = line:match("^ %* ([0-9a-f:]+) *(.- )%[(.-)%] +(%d+%.%d+)")
  11. if mac then
  12. if not flags:match('P') then
  13. counts.total = counts.total + 1
  14. clients[mac:lower()] = true
  15. if flags:match('W') then
  16. counts.wifi = counts.wifi +1
  17. end
  18. end
  19. end
  20. end
  21. function count_iface_stations(iface)
  22. local wifitype = iwinfo.type(iface)
  23. if wifitype == nil then
  24. return
  25. end
  26. local freq = iwinfo[wifitype].frequency(iface)
  27. local key
  28. if freq >= 2400 and freq < 2500 then
  29. key = "wifi24"
  30. elseif freq >= 5000 and freq < 6000 then
  31. key = "wifi5"
  32. else
  33. return
  34. end
  35. for k, v in pairs(iwinfo[wifitype].assoclist(iface)) do
  36. if clients[k:lower()] then
  37. counts[key] = counts[key] + 1
  38. end
  39. end
  40. end
  41. local ifaces = {}
  42. uci:foreach("wireless", "wifi-iface", function(s)
  43. if s.network == "client" and s.mode == "ap" then
  44. count_iface_stations(s.ifname)
  45. end
  46. end)
  47. return counts