动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   Asp → 阅读文章

 ASP ,IP地址分段计算

作者:未知 来源:CSDN 
阅读 115 人次 , 2008-5-8 11:45:00 

<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>"
%>

  
 本文Tags组网  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:asp 利用 xmlhttp 抓取网页内容
· 下一篇:ASP,FSO遍历目录及目录下文件
· VBScript Exit 语句
· ASP作的剪包锤游戏
· Flash和Asp数据库的结合应用
· Global.asa文件的使用及Chat程序
· JScript 方法 - getUTCDay 方法


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077