欢迎光临
我们一直在努力

IP地址分段计算-ASP教程,ASP应用

建站超值云服务器,限时71元/月

/* written by jaron ,2000-01-10 */

/* 原出处:江都资讯网 http://www.jiangdu.net */

/* 转载请注明出处和保留此版权信息 */

/* 欢迎使用sitemanager网站管理系统 http://sitemanager.cnzone.net */

/*相关文章:http://www.csdn.net/develop/read_article.asp?id=19652*/

<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中没有位操作,这样在一个页面中用到了js和vbs,并不好,如果用vbs也可以,不过罗嗦了一些,而且有一点注意,如果在vbs中split("202.102.29.6",","),会得到202,102,29三个数,得不到最后一个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>"

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » IP地址分段计算-ASP教程,ASP应用
分享到: 更多 (0)