请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

asp下IP地址分段计算函数

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
IP地址分段计算
<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>"
%> 

 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
asp下实现IP限制函数代码发布时间:2022-02-05
下一篇:
asp身份证验证代码函数发布时间:2022-02-05
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap