This article mainly introduces the code sharing of asp implementation to check whether the IP address is an intranet or private IP address. It is for those who are also looking for IP judgment. Friends who need it can refer to it.
asp checks whether the ip address is a private/intranet ip address source code.
The intranet/private IP address segment is as follows, as well as the loopback address starting with 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
Implementation code:
<%function IpToNumber(ip)'IP address converted to numbers arr=split(ip,.) IpToNumber=256*256*256*clng(arr(0))+256*256*clng(arr(1))+256 *clng(arr(2))+clng(arr(3))end functionfunction IsPrivateIp(ip)' Determine whether the given IP address is an intranet/private ip address if instr(ip,127.)=1 then'Loopback IP address IsPrivateIp=true:exit function end if ABegin=IpToNumber(10.0.0.0):AEnd=IpToNumber(10.255.255.255)' Class A private IP address BBegin=IpToNumber(172.16.0.0):BEnd=IpToNumber(1 72.31.255.255)'Class B private IP address CBegin=IpToNumber(192.168.0.0):CEnd=IpToNumber(192.168.255.255)'Class C private IP address IpNum=IpToNumber(ip) IsPrivateIp=(ABegin<=IpNum and IpNum<=AEnd) or (BBegin<=IpNum and IpNum<=BEnd) or (CBegin<=IpNum and IpNum<=CEnd)end functionResponse.Write IsPrivateIp(11.255.255.255)&<br >'falseResponse.Write IsPrivateIp(182.255.255.255)&<br>'falseResponse.Write IsPrivateIp(172.30.255.255)&<br>'trueResponse.Write IsPrivateIp(192.168.205.2)&<br>'trueResponse.Write IsPrivateIp(127.168.205.2)'true %>