作家
登录

asp下IP地址分段计算函数

作者: 来源:www.28hudong.com 2013-03-30 08:33:21 阅读 我要评论

IP地址分段计算 <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>" %>

  推荐阅读

  asp下生成目录树结构的类

关于生成目录树结构的类 本程序有两文件test.asp 和tree.asp 还有一些图标文件 1。test.asp 调用类生成树 代码如下 <%@ Language=VBScript %> <html> <head> <link rel="stylesheet" href="tree.css"> <title>tree>>>详细阅读


本文标题:asp下IP地址分段计算函数

地址:http://www.17bianji.com/kaifa2/ASP/32365.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)