手机
当前位置:查字典教程网 >编程开发 >ASP教程 >asp下IP地址分段计算函数
asp下IP地址分段计算函数
摘要:IP地址分段计算functionIPDeCode(EIP){varIp1,Ip2,Ip3,Ip4;Ip1=moveByteR(EIP&0xf...

IP地址分段计算

<scriptlanguage="JScript"Runat="Server">

functionIPDeCode(EIP){

varIp1,Ip2,Ip3,Ip4;

Ip1=moveByteR(EIP&0xff000000,3);

Ip2=moveByteR(EIP&0x00ff0000,2);

Ip3=moveByteR(EIP&0x0000ff00,1);

Ip4=EIP&0x000000ff;

returnIp1+"."+Ip2+"."+Ip3+"."+Ip4;

}

functionmoveByteL(num,bytenum){

returnnum<<=(bytenum*8)

}

functionmoveByteR(num,bytenum){

returnnum>>>=(bytenum*8)

}

</script>

在vbs中没有位操作,这样在一个页面中用到了js和vbs,并不好,如果用vbs也可以,不过罗嗦了一些,而且有一点注意,如果在vbs中split("202.102.29.6","."),会得到202,102,29三个数,得不到最后一个6,所以需要将ip换成split("202.102.29.6"&".",".")

我用vbs做的,由于没有位操作,所以做得比较麻烦

<%

functionip2int(ipstr)

dimiptemp,max

iptemp=split(ipstr&".",".")

max=ubound(iptemp)

ifmax<>4then

exitfunction

endif

dima,b,i

a="&H"

fori=0to3

b=Hex(iptemp(i))

iflen(b)=1then

b="0"&b

endif

a=a&b

next

ip2int=CLng(a)

endfunction

functionint2ip(ip)

dimiptemp,a,ipstr,i,length

iptemp=Hex(ip)

length=8-len(iptemp)

fori=1tolength

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

endfunction

dimtestIP,testInt

testIP="202.102.29.6"

testInt=ip2int(testIP)

response.writetestIP&"willbeencodedto<fontcolor=red>"&testInt&"</font><br>"

response.writetestIP&"willbedencodedto<fontcolor=red>"&int2ip(testInt)&"</font><br>"

%>

【asp下IP地址分段计算函数】相关文章:

asp 常用函数用法

asp论坛在线人数统计研究

asp 检测服务器所安装组件

asp中一段防SQL注入的通用脚本

asp之字符串操作函数

ASP常用函数:HTMLDecode

ASP处理查询超时的解决函数

一个实用asp分页函数

asp 中常用的文件处理函数

asp中正则表达式过滤html代码函数

精品推荐
分类导航