OpenWrt之自定义Hostname
找到对应的代码,在feeds/./luci/modules/luci-lua-runtime/luasrc/sys.lua
中,有
cur:foreach("dhcp", "dnsmasq",
function(s)
if s.leasefile and fs.access(s.leasefile) then
for e in io.lines(s.leasefile) do
mac, ip, name = e:match("^%d+ (%S+) (%S+) (%S+)")
mac = luci.ip.checkmac(mac)
if mac and ip then
_add(what, mac, ip, nil, name ~= "*" and name)
end
end
end
end
)
查看示例:
root@OpenWrt:/# cat /tmp/dhcp.leases
1706897826 7e:56:11:9b:48:08 192.168.2.153 * 01:7e:56:11:9b:48:08
根据MAC地址反查:
local function get_name_by_(mac)
local dft_name = "*"
if type(mac) ~= "string" then
return dft_name
end
mac = string.gsub(mac, ":", "")
if not fs.access("/etc/config/access_client") then
luci.util.execi("touch /etc/config/access_client")
end
local uci_r = uci.cursor()
local name = uci_r:get("access_client", mac, "name")
return type(name) == "string" and name or dft_name
end
if mac and ip then
if name == "*" then
name = get_name_by_(mac)
end
_add(what, mac, ip, nil, name ~= "*" and name)
end
配置内容参考:
root@OpenWrt:/tmp# cat /etc/config/access_client
config mac '7e56119b4808'
option name 'iPhone15ProMax'
标签:end,name,自定义,ip,Hostname,access,mac,OpenWrt
From: https://www.cnblogs.com/adam-ma/p/18003231