ethinfo: fix ipheth error
This commit is contained in:
parent
d12ebf7386
commit
364c514d81
@ -7,33 +7,43 @@ 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
|
||||
if ifname:match("^(eth%d+)$") == ifname then
|
||||
local status, speed, duplex
|
||||
|
||||
status = stat.carrier and "yes" or "no"
|
||||
status = stat.carrier and "yes" or "no"
|
||||
|
||||
if stat.speed == nil or stat.speed:sub(1, 1) == "-" then
|
||||
speed = "-"
|
||||
else
|
||||
speed = stat.speed:sub(1, -2) .. "Mb/s"
|
||||
end
|
||||
|
||||
if not stat.carrier then
|
||||
duplex = "-"
|
||||
elseif stat.speed:sub(-1) == "F" then
|
||||
duplex = "Full"
|
||||
else
|
||||
duplex = "Half"
|
||||
end
|
||||
|
||||
eth_info[#eth_info+1] = { name = ifname, status = status,
|
||||
speed = speed, duplex = duplex }
|
||||
if status == "yes" and stat.speed == nil then
|
||||
speed = "-"
|
||||
elseif stat.speed == nil or stat.speed:sub(1, 1) == "-" then
|
||||
speed = "-"
|
||||
else
|
||||
speed = stat.speed:sub(1, -2) .. "Mb/s"
|
||||
end
|
||||
|
||||
if not stat.carrier then
|
||||
duplex = "-"
|
||||
elseif stat.speed == nil then
|
||||
duplex = "-"
|
||||
elseif stat.speed:sub(-1) == "F" then
|
||||
duplex = "Full"
|
||||
else
|
||||
duplex = "Half"
|
||||
end
|
||||
|
||||
eth_info[#eth_info + 1] = {
|
||||
name = ifname,
|
||||
status = status,
|
||||
speed = speed,
|
||||
duplex = duplex
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(eth_info,
|
||||
function(a, b)
|
||||
return a.name < b.name
|
||||
end)
|
||||
table.sort(
|
||||
eth_info,
|
||||
function(a, b)
|
||||
return a.name < b.name
|
||||
end
|
||||
)
|
||||
|
||||
print(jsonc.stringify(eth_info))
|
||||
|
Loading…
x
Reference in New Issue
Block a user