欢迎光临
我们一直在努力

ip限制函数

建站超值云服务器,限时71元/月

大家如果还有好的建议算法,就联系我!!:)

******************************

function checkip(cinput_ip,cbound_ip)

created by qqdao, qqdao@263.net 2001/11/28

说明:首先需要根据;号循环,然后判断是否含有"-",如果有则进行拆分处理,最后判断是否在范围内

参数: cinput_ip,代检查的ip

cbound_ip,给定的范围格式为,单个ip,和范围ip,范围ip最后使用”-“分割,如果是“*”则必须放到最后一位

每个范围后添加":allow"表示允许登陆,添加":refuse"表示拒绝登陆。多个范围用”;“隔开

例如192.168.1*.*:allow;192.168.1.1:allow;192.168.1.1-10:refuse"

返回值: true/false

更新:2001/12/05 支持allow,refuse支持’*‘,不想对?支持,因为和*差不多

******************************

function checkip(cinput_ip,cbound_ip)

dim csingle_ip,ctemp_ip,cstart_ip,cend_ip

checkip = false

csingle_ip=split(cbound_ip,";")

for i=0 to ubound(csingle_ip)

if instr(csingle_ip(i),"refuse") <> 0 then 就是拒绝了

ctemp_ip = left(csingle_ip(i),instr(csingle_ip(i),":")-1)

if instr(ctemp_ip,"*") <> 0 then 是宽范围

cstart_ip = left(ctemp_ip,instr(ctemp_ip,"*")-1)

if left(cinput_ip,len(cstart_ip))=cstart_ip then

checkip = false

exit function

end if

end if

if instr(ctemp_ip,"-") = 0 then

cstart_ip = ctemp_ip

cend_ip = ctemp_ip

else

cstart_ip = left(ctemp_ip,instr(ctemp_ip,"-")-1)

cend_ip = left(cstart_ip,instrrev(cstart_ip,".")-1)+"."+mid(ctemp_ip,instr(ctemp_ip,"-")+1)

end if

if ip2str(cinput_ip)>=ip2str(cstart_ip) and ip2str(cinput_ip)<=ip2str(cend_ip) then

checkip = false

exit function

end if

elseif instr(csingle_ip(i),"allow") <> 0 then 允许

ctemp_ip = left(csingle_ip(i),instr(csingle_ip(i),":")-1)

if instr(ctemp_ip,"*") <> 0 then 是宽范围

cstart_ip = left(ctemp_ip,instr(ctemp_ip,"*")-1)

if left(cinput_ip,len(cstart_ip))=cstart_ip then

checkip = true

end if

end if

if instr(ctemp_ip,"-") = 0 then

cstart_ip = ctemp_ip

cend_ip = ctemp_ip

else

cstart_ip = left(ctemp_ip,instr(ctemp_ip,"-")-1)

cend_ip = left(cstart_ip,instrrev(cstart_ip,".")-1)+"."+mid(ctemp_ip,instr(ctemp_ip,"-")+1)

end if

if ip2str(cinput_ip)>=ip2str(cstart_ip) and ip2str(cinput_ip)<=ip2str(cend_ip) then

checkip =true

else

checkip =false

end if

end if

next

end function

******************************

function ip2str(cip)

created by qqdao, qqdao@263.net 2001/11/28

参考动网ip算法

参数:cip ip地址

返回值: 转换后数值

******************************

function ip2str(cip)

dim str1,str2,str3,str4

dim cip_temp

if cip="127.0.0.1" then cip="192.168.0.1"

str1=left(cip,instr(cip,".")-1)

cip_temp=mid(cip,instr(cip,".")+1)

str2=left(cip_temp,instr(cip_temp,".")-1)

cip_temp=mid(cip_temp,instr(cip_temp,".")+1)

str3=left(cip_temp,instr(cip_temp,".")-1)

str4=mid(cip_temp,instr(cip_temp,".")+1)

if isnumeric(str1)=0 or isnumeric(str2)=0 or isnumeric(str3)=0 or isnumeric(str4)=0 then

else

ip2str=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1

end if

end function

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ip限制函数
分享到: 更多 (0)

相关推荐

  • 暂无文章