You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

  1. #!/usr/bin/lua
  2. local function get_basic_net_info(network, iface, accumulator)
  3. local net = network:get_network(iface)
  4. local device = net and net:get_interface()
  5. if device then
  6. accumulator["uptime"] = net:uptime()
  7. accumulator["iface"] = device:name()
  8. accumulator["mac"] = device:mac()
  9. accumulator["rx_bytes"] = device:rx_bytes()
  10. accumulator["tx_bytes"] = device:tx_bytes()
  11. accumulator["ipaddrs"] = {}
  12. for _, ipaddr in ipairs(device:ipaddrs()) do
  13. accumulator.ipaddrs[#accumulator.ipaddrs + 1] = {
  14. addr = ipaddr:host():string(),
  15. netmask = ipaddr:mask():string()
  16. }
  17. end
  18. end
  19. end
  20. local function get_wifi_info(network, iface, accumulator)
  21. local net = network:get_wifinet(iface)
  22. if net then
  23. local dev = net:get_device()
  24. if dev then
  25. accumulator["mode"] = net:active_mode()
  26. accumulator["ssid"] = net:active_ssid()
  27. accumulator["encryption"] = net:active_encryption()
  28. accumulator["quality"] = net:signal_percent()
  29. end
  30. end
  31. end
  32. local function collect_wifi_info()
  33. local network = require"luci.model.network".init()
  34. local accumulator = {}
  35. get_basic_net_info(network, "lan", accumulator)
  36. get_wifi_info(network, "wlan0", accumulator)
  37. return accumulator
  38. end
  39. local info = collect_wifi_info()
  40. print("Current WiFi configuration")
  41. if info.ssid then
  42. print("SSID: " .. info.ssid)
  43. end
  44. if info.mode then
  45. print("Mode: " .. info.mode)
  46. end
  47. if info.quality then
  48. print("Signal: " .. info.quality .. "%")
  49. end
  50. if info.encryption then
  51. print("Encryption method: " .. info.encryption)
  52. end
  53. if info.iface then
  54. print("Interface name: " .. info.iface)
  55. end
  56. if info.uptime then
  57. print("Active for: " .. math.floor(info.uptime / 60) .. " minutes")
  58. end
  59. if #info.ipaddrs > 0 then
  60. print("IP address: " .. info.ipaddrs[1].addr .. "/" .. info.ipaddrs[1].netmask)
  61. end
  62. if info.mac then
  63. print("MAC address: " .. info.mac)
  64. end
  65. if info.rx_bytes and info.tx_bytes then
  66. print("RX/TX: " .. math.floor(info.rx_bytes / 1024) .. "/" .. math.floor(info.tx_bytes / 1024) .. " KBs")
  67. end