加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

ASP中实现限制IP的函数解读

发布时间:2023-09-15 15:03:21 所属栏目:Asp教程 来源:
导读:'Function CheckIp(cInput_Ip,cBound_Ip)

'Created by qqdao, qqdao@263.net 2001/11/28

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

&
'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
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章