脚本调用方式调用方式

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

戴马师
17 声望0 粉丝

启用Redis缓存优化您的网站访问速度


引用和评论

0 条评论