Lua 获取本地IP
作者:互联网
Lua 获取本地IP
1、代码:
--[[ author:lizhm datetime:20220706 09:38:00 description:获取本地IP ]] -- 引入socket模块 local socket = require("socket") -- 打印时间 print(os.time()) -- 功能函数 function getIp(hostname) local ip, resolved = socket.dns.toip(hostname) -- 初始化表listTab local listTab = {} for k, v in ipairs(resolved.ip) do -- listTab表中插入值v table.insert(listTab, v) end return listTab end print(unpack(getIp('localhost'))) print(unpack(getIp(socket.dns.gethostname())))
结果:
标签:socket,--,IP,listTab,Lua,本地,print,getIp,local 来源: https://www.cnblogs.com/lizm166/p/16449611.html