0
点赞
收藏
分享

微信扫一扫

lua中实现判断是否为局域网IP

非凡兔 2023-02-07 阅读 110

脚本调用方式调用方式

print(is_lan_ip("192.168.1.1")) -- true
print(is_lan_ip("8.8.8.8")) -- false

函数实现过程

function is_lan_ip(ip)
-- Split the IP address into its octets
local octets = {}
for octet in ip:gmatch("%d+") do
table.insert(octets, tonumber(octet))
end

-- Check if the IP is in the range of private IP addresses
if octets[1] == 10 then
return true
elseif octets[1] == 172 and octets[2] >= 16 and octets[2] <= 31 then
return true
elseif octets[1] == 192 and octets[2] == 168 then
return true
else
return false
end
end

举报

相关推荐

0 条评论