asp下IP地址分段計(jì)算函數(shù)
<script language="JScript" Runat="Server">
function IPDeCode(EIP){
var Ip1,Ip2,Ip3,Ip4;
Ip1 = moveByteR(EIP & 0xff000000,3);
Ip2 = moveByteR(EIP & 0x00ff0000,2);
Ip3 = moveByteR(EIP & 0x0000ff00,1);
Ip4 = EIP & 0x000000ff;
return Ip1 + "." + Ip2 + "." + Ip3 + "." + Ip4;
}
function moveByteL(num,bytenum){
return num <<= (bytenum*8)
}
function moveByteR(num,bytenum){
return num >>>= (bytenum*8)
}
</script>
在vbs中沒(méi)有位操作,這樣在一個(gè)頁(yè)面中用到了js和vbs,并不好,如果用vbs也可以,不過(guò)羅嗦了一些,而且有一點(diǎn)注意,如果在vbs中split("202.102.29.6","."),會(huì)得到202,102,29三個(gè)數(shù),得不到最后一個(gè)6,所以需要將ip換成split("202.102.29.6" & ".",".")
我用vbs做的,由于沒(méi)有位操作,所以做得比較麻煩
<%
function ip2int(ipstr)
dim iptemp,max
iptemp = split(ipstr&".",".")
max = ubound(iptemp)
if max <> 4 then
exit function
end if
dim a,b,i
a = "&H"
for i = 0 to 3
b = Hex(iptemp(i))
if len(b) = 1 then
b = "0"&b
end if
a = a&b
next
ip2int = CLng(a)
end function
function int2ip(ip)
dim iptemp,a,ipstr,i,length
iptemp = Hex(ip)
length = 8 - len(iptemp)
for i = 1 to length
iptemp = "0" & iptemp
next
a = left(iptemp,2)
a = "&H" & a
i = CInt(a)
a = CStr(i)
ipstr = a & "."
a = mid(iptemp,3,2)
a = "&H" & a
i = CInt(a)
a = CStr(i)
ipstr = ipstr & a & "."
a = mid(iptemp,5,2)
a = "&H" & a
i = CInt(a)
a = CStr(i)
ipstr = ipstr & a & "."
a = right(iptemp,2)
a = "&H" & a
i = CInt(a)
a = CStr(i)
ipstr = ipstr & a
int2ip = ipstr
end function
dim testIP,testInt
testIP="202.102.29.6"
testInt = ip2int(testIP)
response.write testIP & " will be encoded to <font color=red>" & testInt & "</font><br>"
response.write testIP & " will be dencoded to <font color=red>" & int2ip(testInt) & "</font><br>"
%>
相關(guān)文章
用ASP實(shí)現(xiàn)分級(jí)權(quán)限控制
用ASP實(shí)現(xiàn)分級(jí)權(quán)限控制...2007-09-09關(guān)于ASP生成偽參數(shù)技巧 簡(jiǎn)潔實(shí)用的偽(僞)參數(shù)
關(guān)于ASP生成偽參數(shù)技巧 簡(jiǎn)潔實(shí)用的偽(僞)參數(shù)...2007-11-11如何從數(shù)據(jù)庫(kù)中隨機(jī)取出10條記錄的方法
如何從數(shù)據(jù)庫(kù)中隨機(jī)取出10條記錄的方法...2007-01-01asp在服務(wù)器把 XML 轉(zhuǎn)換為 XHTML的實(shí)現(xiàn)代碼
asp在服務(wù)器把 XML 轉(zhuǎn)換為 XHTML的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-11-11用ASP+DLL實(shí)現(xiàn)WEB方式修改服務(wù)器時(shí)間
用ASP+DLL實(shí)現(xiàn)WEB方式修改服務(wù)器時(shí)間...2006-09-09asp之自動(dòng)閉合HTML/ubb標(biāo)簽函數(shù)附簡(jiǎn)單注釋
這樣的功能就是實(shí)現(xiàn)一般html,ubb標(biāo)簽的閉合,以前在pjblog中見(jiàn)過(guò),一直沒(méi)用,這個(gè)函數(shù)不錯(cuò),建議可以參考下pjblog中的函數(shù)。2009-01-01ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向
這篇文章主要介紹了ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向,需要的朋友可以參考下2016-12-12動(dòng)網(wǎng)防惡意廣告比較有效的辦法附asp代碼
動(dòng)網(wǎng)防惡意廣告比較有效的辦法附asp代碼...2007-05-05