IP地址分段计算 (转)

IP地址分段计算 (转)[@more@]

/* written by Jaron ,2000-01-10 */
/* 原出处:江都资讯网 .NET/">http://www.jiangdu.net */
/* 转载请注明出处和保留此版权信息 */
/* 欢迎使用SiteManager网站管理系统 http://sitemanager.cnzone.net  */
/*相关文章:ASP?id=19652*/">http://www.csdn.net/Develop/read_article.asp?id=19652*/


 function moveByteL(num,bytenum){
  return num <<= (bytenum*8)
 }

 function moveByteR(num,bytenum){
  return num >>>= (bytenum*8)
 }
 


在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 " & testInt & "
"
response.write testIP & " will be dencoded to " & int2ip(testInt) & "
"
%>


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10748419/viewspace-959176/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10748419/viewspace-959176/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值