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


猜你喜欢
Pytest测试框架基本使用方法详解
2022-06-23 20:49:04
微信js-sdk 录音功能的示例代码
2024-04-22 13:04:45

vue项目中常用解决跨域的方法总结(CORS和Proxy)
2024-04-28 09:33:05
MySQL数据库INNODB表损坏修复处理过程分享
2024-01-16 10:59:56
如何测试字符串的长度?
2009-11-11 20:02:00
详解Vue项目的打包方式
2024-05-09 09:21:24

一文深入了解Python中的继承知识点
2023-01-16 19:57:16

Python opencv医学处理的实现过程
2021-11-19 01:51:47

MySQL判别InnoDB表是独立表空间还是共享表空间的方法详解
2024-01-18 14:23:34

python中pickle模块浅析
2022-02-06 06:27:38
详解thinkphp+redis+队列的实现代码
2024-05-11 10:08:34

Python开发的HTTP库requests详解
2021-09-06 19:08:09
一段Asp301重定向过程代码
2010-05-04 16:38:00
Golang自定义结构体转map的操作
2024-05-08 10:21:39
Python类装饰器实现方法详解
2021-11-15 20:01:05
asp生成带有样式的word文件方法
2011-04-18 10:30:00
Python中使用asyncio 封装文件读写
2022-11-13 03:18:12
Python常用数据结构和公共方法技巧总结
2021-10-18 06:02:01

Python字符串、整数、和浮点型数相互转换实例
2023-09-20 18:05:52
Python基于域相关实现图像增强的方法教程
2023-08-24 15:30:22
