diff --git a/package/lean/autocore/files/arm/sbin/ethinfo b/package/lean/autocore/files/arm/sbin/ethinfo index 6a195232a..3472e6812 100755 --- a/package/lean/autocore/files/arm/sbin/ethinfo +++ b/package/lean/autocore/files/arm/sbin/ethinfo @@ -1,40 +1,45 @@ #!/usr/bin/lua --- Copyright (C) 2022-2023 Tianling Shen --- Copyright (C) 2022-2023 Lean +-- Copyright (C) 2022 ImmortalWrt.org local util = require "luci.util" local jsonc = require "luci.jsonc" local eth_info = {} local ifname, stat + for ifname, stat in pairs(util.ubus("network.device", "status")) do - if ifname:match("^(eth%d+)$") == ifname then - local status, speed, duplex + while true do + if (ifname:match("^(br-.+)$")) == ifname then + break + else + local status, speed, duplex - status = stat.carrier and 1 or 0 + if(stat.speed ~= nil) then + status = stat.carrier and 1 or 0 - if not stat.carrier or not stat.speed or stat.speed:sub(1, 1) == "-" or stat.speed:find("65535") then - speed = " - " - else - speed = stat.speed:sub(1, -2) .. "Mb/s" - end + if stat.speed:sub(1, 1) == "-" then + speed = " - " + else + speed = stat.speed:sub(1, -2) .. "Mb/s" + end - if speed == " - " then - duplex = 0 - elseif stat.speed:sub(-1) == "F" then - duplex = 1 - else - duplex = 0 - end + if stat.carrier and stat.speed:sub(-1) == "F" then + duplex = 1 + else + duplex = 0 + end - eth_info[#eth_info+1] = { name = ifname, status = status, - speed = speed, duplex = duplex } - end + eth_info[#eth_info+1] = { name = ifname, status = status, + speed = speed, duplex = duplex } + end + break + end + end end table.sort(eth_info, - function(a, b) - return a.name < b.name - end) + function(a, b) + return a.name < b.name + end) print(jsonc.stringify(eth_info))