asp下IP地址分段計(jì)算函數(shù)
更新時(shí)間:2007年11月24日 22:03:32 作者:
IP地址分段計(jì)算
<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中沒有位操作,這樣在一個(gè)頁面中用到了js和vbs,并不好,如果用vbs也可以,不過羅嗦了一些,而且有一點(diǎn)注意,如果在vbs中split("202.102.29.6","."),會(huì)得到202,102,29三個(gè)數(shù),得不到最后一個(gè)6,所以需要將ip換成split("202.102.29.6" & ".",".")
我用vbs做的,由于沒有位操作,所以做得比較麻煩
<%
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>"
%>
<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中沒有位操作,這樣在一個(gè)頁面中用到了js和vbs,并不好,如果用vbs也可以,不過羅嗦了一些,而且有一點(diǎn)注意,如果在vbs中split("202.102.29.6","."),會(huì)得到202,102,29三個(gè)數(shù),得不到最后一個(gè)6,所以需要將ip換成split("202.102.29.6" & ".",".")
我用vbs做的,由于沒有位操作,所以做得比較麻煩
<%
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)文章
使用AJAX實(shí)現(xiàn)UTF8編碼表單提交到GBK編碼腳本無亂碼的解決方法
這篇文章主要介紹了用AJAX實(shí)現(xiàn),多個(gè)不同編碼的項(xiàng)目(GBK,UTF8)互相通過 POST/GET 匯總表單數(shù)據(jù)。最終實(shí)現(xiàn) 使用同一個(gè)頁面接收 不同編碼的 表單(GBK,UTF8),特別適合 JS 采集項(xiàng)目,需要的朋友可以參考下2020-09-09
Highlight patterns within strings
Highlight patterns within strings...2007-04-04
使用innerHTML時(shí)注意處理空格和回車符(asp后臺(tái)處理)
innerHTML中如果包含空格和回車都會(huì)被認(rèn)為是段落的結(jié)束,造成程序運(yùn)行出錯(cuò),解決辦法,輸出的時(shí)候?qū)⒖崭窈突剀囂鎿Q掉,方便js調(diào)用。2011-08-08
.NET中的6種定時(shí)器的基本用法和特點(diǎn)
.NET中至少有6種定時(shí)器,每一種定時(shí)器都有它的用途和特點(diǎn),根據(jù)定時(shí)器的應(yīng)用場(chǎng)景,可以分為UI相關(guān)的定時(shí)器和UI無關(guān)的定時(shí)器,本文將簡(jiǎn)單介紹這6種定時(shí)器的基本用法和特點(diǎn),感興趣的朋友一起看看吧2023-12-12
C語言數(shù)組添加和刪除元素的實(shí)現(xiàn)
這篇文章主要介紹了C語言數(shù)組添加和刪除元素的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02

