富贵论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

手机号码,快捷登录

广告位招租qq41463402
查看: 12|回复: 0

[教程] 关于ASP实现IP地址分段计算的实例代码分享

[复制链接]

1万

主题

1231

回帖

4万

积分

赞助会员

UID
931
金钱
0 点
威望
0 点
贡献
18166 点
宣传
0 人
买家
0 元
卖家
0 元
注册时间
2017-5-26
最后登录
2024-7-25

资讯达人勋章富贵吧MM勋章赞助会员勋章签到达人勋章

发表于 2024-4-24 02:10 | 显示全部楼层 |阅读模式

以下是一个关于ASP实现IP地址分段计算的实例代码分享,大家可以自己试试,希望能够帮助到大家。

在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) & "
"

%>

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|富贵论坛 ( 琼ICP备2022019866号-1 )

GMT+8, 2024-7-27 10:23 , Processed in 0.127413 second(s), 32 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表