脚本调用方式调用方式
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
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。