interfaces 551 B

123456789101112131415161718192021222324
  1. #!/usr/bin/lua
  2. util = require 'luci.util'
  3. json = require 'luci.jsonc'
  4. fs = require 'nixio.fs'
  5. io.write("Access-Control-Allow-Origin: *\n")
  6. io.write("Content-type: application/json\n\n")
  7. list = util.exec('batctl if')
  8. interfaces = {}
  9. for _, line in ipairs(util.split(list)) do
  10. ifname = line:match('^(.-):')
  11. if ifname ~= nil then
  12. pcall(function()
  13. local address = util.trim(fs.readfile('/sys/class/net/' .. ifname .. '/address'))
  14. interfaces[ifname] = { address = address }
  15. end)
  16. end
  17. end
  18. io.write(json.stringify(interfaces))