首页 > 其他分享 >OpenWrt之自定义Hostname

OpenWrt之自定义Hostname

时间:2024-02-02 15:25:03浏览次数:23  
标签:end name 自定义 ip Hostname access mac OpenWrt

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

相关文章

  • TP5框架 之自定义标签
    一、创建控制器<?phpnamespaceapp\common\taglib;usethink\auth\Auth;usethink\template\TagLib;classMyTagextendsTagLib{protected$tags=['auth'=>['attr'=>'rule','close'=>1......
  • OpenWrt之自定义Firmware Version
    OpenWrt之自定义FirmwareVersion首先,找到显示FirmwareVersion的代码,在/usr/lib/lua/luci/version.lua中:root@OpenWrt:/usr/lib/lua/luci#catversion.lualocalpcall,dofile,_G=pcall,dofile,_Gmodule"luci.version"ifpcall(dofile,"/etc/openwrt_rele......
  • OpenWrt之Aria2报错
    OpenWrt之Aria2报错具体报错如下:FriFeb213:48:022024daemon.infoaria2c[6519]:jail:exec-ing/usr/bin/aria2cFriFeb213:48:022024daemon.erraria2c[6519]:ExceptioncaughtFriFeb213:48:022024daemon.erraria2c[6519]:Exception:[Platform.cc:125]......
  • 如何创建自定义启动器
    对于要自定义启动器,我们首先分析下此依赖结构,随后再创建maven项目就拿SpringBoot起步依赖来说。1.首先需要创建一个父工程如名称aliyun-parentd,编写pom.xml文件中的内容(1).修改打包方式为pom(2).继承springboot起步依赖名称是spring-boot-parent-starter2.后面需要创建你所......
  • 自定义jdk镜像
    1、安装docker这里使用Ubuntu系统安装docker,方便一点(偷懒)apt-getinstalldocker.io-y安装不了可以试试阿里云镜像源,在/etc/apt/sources.list.d/下新增文件:aliyun.sources.list,写入如下内容(ubuntu22.04示例,其他版本参考:ubuntu镜像_ubuntu下载地址_ubuntu安装教程-阿里巴巴......
  • 无边框 自定义页面 圆角 自定义关闭按钮 wfp 钱包夹
    无边框自定义页面圆角 自定义关闭按钮wfp钱包夹C#.net4.8wpfSqlServer2012消息队列Redis 来源银柱网-李银柱个人博客http://www.liyinzhu.com......
  • vue3,封装检测元素大小变化的自定义指令
    1//resizeObserver.ts2//监听元素大小变化的指令3constmap=newWeakMap()4constob=newResizeObserver((entries)=>{5for(constentryofentries){6//获取dom元素的回调7consthandler=map.get(entry.target)8//存在回调函......
  • 博客园自定义主题
    开源项目非常感谢作者的工作,下面是github主页和官方文档https://github.com/BNDong/Cnblogs-Theme-SimpleMemoryhttps://bndong.github.io/Cnblogs-Theme-SimpleMemory/v2.1/dist/三方教程https://www.cnblogs.com/chenkeer/p/15193179.html常见错误说明修改后,博客页面一......
  • Day63 异常03:自定义异常及经验小结
    自定义异常使用Java内置的异常类可以描述在编程时出现的大部分异常情况。除此之外,用户还可以自定义异常。用户自定义异常类,只需继承Exception类即可。在程序中使用自定义异常类,大体可分为以下几个步骤:创建自定义异常类。在方法中通过throw关键字抛出异常对象。如果在当......
  • Java调用ChatGPT(基于SpringBoot和Vue)实现连续对话、流式输出和自定义baseUrl
     源码及更详细的介绍说明参见Git上的README.md文档https://github.com/asleepyfish/chatgpt本文Demo(SpringBoot和Main方法Demo均包括)的Git地址:https://github.com/asleepyfish/chatgpt-demo流式输出结合Vue前端的Demo的Git地址:https://github.com/asleepyfish/chatg......