wifi 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. local json = require 'luci.json'
  2. local util = require 'luci.util'
  3. local fs = require 'nixio.fs'
  4. local iwinfo = require 'iwinfo'
  5. function neighbours(iface)
  6. local stations = {}
  7. for k, v in pairs(iface.iw.assoclist(iface.ifname)) do
  8. stations[k:lower()] = { signal = v.signal
  9. , noise = v.noise
  10. , inactive = v.inactive
  11. }
  12. end
  13. return stations
  14. end
  15. function interfaces()
  16. local interfaces = {}
  17. for _, line in ipairs(util.split(util.exec('batctl if'))) do
  18. ifname = line:match('^(.-): active')
  19. if ifname ~= nil then
  20. pcall(function()
  21. local address = util.trim(fs.readfile('/sys/class/net/' .. ifname .. '/address'))
  22. local wifitype = iwinfo.type(ifname)
  23. if wifitype ~= nil then
  24. interfaces[address] = { ifname = ifname, iw = iwinfo[wifitype] }
  25. end
  26. end)
  27. end
  28. end
  29. return interfaces
  30. end
  31. local wifi = {}
  32. for address, iface in pairs(interfaces()) do
  33. wifi[address] = { neighbours = neighbours(iface) }
  34. end
  35. return wifi