asp检查ip地址是否为私有/内网ip地址源代码。
内网/私有ip地址网段如下,还有127开头的回环地址:
10.0.0.0-10.255.255.255
172.16.0.0—172.31.255.255
192.168.0.0-192.168.255.255
实现代码:
<%
function iptonumber(ip)'ip地址转为数字
arr=split(ip,".")
iptonumber=256*256*256*clng(arr(0))+256*256*clng(arr(1))+256*clng(arr(2))+clng(arr(3))
end function
function isprivateip(ip)'判断给定的ip地址是否内网/私有ip地址
if instr(ip,"127.")=1 then'回环ip地址
isprivateip=true:exit function
end if
abegin=iptonumber("10.0.0.0"):aend=iptonumber("10.255.255.255")'a类私有ip地址
bbegin=iptonumber("172.16.0.0"):bend=iptonumber("172.31.255.255")'b类私有ip地址
cbegin=iptonumber("192.168.0.0"):cend=iptonumber("192.168.255.255")'c类私有ip地址
ipnum=iptonumber(ip)
isprivateip=(abegin<=ipnum and ipnum<=aend) or (bbegin<=ipnum and ipnum<=bend) or (cbegin<=ipnum and ipnum<=cend)
end function
response.write isprivateip("11.255.255.255")&"<br>"'false
response.write isprivateip("182.255.255.255")&"<br>"'false
response.write isprivateip("172.30.255.255")&"<br>"'true
response.write isprivateip("192.168.205.2")&"<br>"'true
response.write isprivateip("127.168.205.2")'true
%>
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!