ASP ,IP地址分段计算
来源:CSDN 时间:2008-04-13 06:55: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>"
%>
标签:ip,地址,vbs,asp
0
投稿
猜你喜欢
PL/SQL实现Oracle数据库任务调度
2010-07-20 12:57:00
asp使用模板生成静态页面方法详解
2007-09-24 12:29:00
Oracle 随机数
2009-06-04 10:01:00
教你怎样在Oracle数据库中高速导出/导入
2009-02-04 16:59:00
SQL Server 2005五个动态管理对象
2009-02-24 17:41:00
打分进化史
2009-12-24 12:20:00
delete from online where datediff
2009-06-07 18:46:00
如何创建CSS的对象,获取合适的粒度
2010-07-09 13:10:00
IE 8 提出“超级标准模式”
2008-01-24 19:26:00
另类解读SQL Server中的DateTime数据类型
2009-01-06 11:22:00
java.sql.SQLException: 内部错误: Unable to construct a Datum from the specified input
2010-07-16 13:23:00
SqlServer参数化查询之where in和like实现详解
2012-05-22 18:10:50
根据Dreamweaver里的ToolTip代码改进的提示框
2008-11-27 12:19:00
css中absolute与relative的区别
2007-11-17 08:04:00
如何把数据库的记录输出到表格去?
2009-11-06 13:37:00
javascript新闻图片轮换类
2009-01-09 12:57:00
ASP:使用ImageMagickObject组件制作缩略图
2008-10-21 12:21:00
Cookies 欺骗漏洞的防范方法(vbs+js 实现)
2011-03-09 11:09:00
MooTools的Cookie类太“自作聪明”了
2008-11-13 12:59:00
如何用ASP输出HTML文件?
2010-06-11 20:01:00