ethinfo: fix ipheth error

This commit is contained in:
Bard 2023-10-09 12:14:20 +08:00 committed by GitHub
parent d12ebf7386
commit 364c514d81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,9 @@ for ifname, stat in pairs(util.ubus("network.device", "status")) do
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 if status == "yes" and stat.speed == nil then
speed = "-"
elseif stat.speed == nil or stat.speed:sub(1, 1) == "-" then
speed = "-" speed = "-"
else else
speed = stat.speed:sub(1, -2) .. "Mb/s" speed = stat.speed:sub(1, -2) .. "Mb/s"
@ -20,20 +22,28 @@ for ifname, stat in pairs(util.ubus("network.device", "status")) do
if not stat.carrier then if not stat.carrier then
duplex = "-" duplex = "-"
elseif stat.speed == nil then
duplex = "-"
elseif stat.speed:sub(-1) == "F" then elseif stat.speed:sub(-1) == "F" then
duplex = "Full" duplex = "Full"
else else
duplex = "Half" duplex = "Half"
end end
eth_info[#eth_info+1] = { name = ifname, status = status, eth_info[#eth_info + 1] = {
speed = speed, duplex = duplex } name = ifname,
status = status,
speed = speed,
duplex = duplex
}
end end
end end
table.sort(eth_info, table.sort(
eth_info,
function(a, b) function(a, b)
return a.name < b.name return a.name < b.name
end) end
)
print(jsonc.stringify(eth_info)) print(jsonc.stringify(eth_info))