wifi 1.0 KB

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