asp檢查ip地址是否為私有/內(nèi)網(wǎng)ip地址源代碼。
內(nèi)網(wǎng)/私有IP地址網(wǎng)段如下,還有127開(kāi)頭的回環(huán)地址:
10.0.0.0-10.255.255.255
172.16.0.0—172.31.255.255
192.168.0.0-192.168.255.255
實(shí)現(xiàn)代碼:
% function IpToNumber(ip)'IP地址轉(zhuǎn)為數(shù)字 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地址是否內(nèi)網(wǎng)/私有ip地址 if instr(ip,"127.")=1 then'回環(huán)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 %>
標(biāo)簽:揭陽(yáng) 唐山 汕頭 海南 佛山 撫州 攀枝花 鶴崗
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp實(shí)現(xiàn)檢查ip地址是否為內(nèi)網(wǎng)或者私有ip地址的代碼分享》,本文關(guān)鍵詞 asp,實(shí)現(xiàn),檢查,地址,是否,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。