当前位置: 首页 > 图文教程 > 网络编程 > ASP > IP地址分段计算

ASP
Dom遍历XML的一个例子,结果为树状结构
[原创]如何回到先前的页面的方法多中语言
几个经典的ASP应用
pjblog实现类似CMS的首页调用
PJblog友情链接LOGO地址失效的解决
ASP程序给上传的图片增添水印效果!
127.0.0.1无法访问,没有权限: GetObject
PJBLOG使用技巧
ASP数据库连接方式大全
ASP辅助代码
垃圾引用防治补丁以及发送引用修正补丁的自动安装程序
发一个采集(小偷)用的类,ASP+缓存实现
利用ASPUPLOAD,ASPJPEG实现图片上传自动生成缩略图及加上水印
后台管理登录篇-asp设计与数据库
使用Flash DownLoad编写采集器(之突破防盗连下载音乐文件)
[原创]随机增加网站点击的一个不错的方法
javascript asp教程第二课--转义字符
javascript asp教程第三课 new String() 构造器
javascript asp教程第六课-- response方法
简单的ASP中经常用到的代码[推荐]

ASP 中的 IP地址分段计算


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 91 ::
收藏到网摘: n/a

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