ASP中实现限制IP的函数详解
2023-06-13 09:13:55 时间
"******************************
"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
"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
相关文章
- zblog利用ip地址物理化插件实现评论显示IP归属地的方法(最新兼容IPV4/V6)
- 精确的IP定位:MYSQL字段配置(ip的mysql字段)
- ASP结合MySQL:实现快速数据库连接(asp如何连接mysql)
- Linux 自动获取IP功能的实现(linux自动获取ip)
- 使用 ASP 连接 MS SQL 服务器(asp连接mssql)
- Linux:实现动态IP变化(linux动态ip)
- 登录MySQL多IP登录:实现安全连接的新方式(mysql多个ip)
- 修改Oracle主机名IP修改实现安全运行(oracle主机名ip)
- Linux系统IP快速配置指南(linux系统ip配置)
- 冲突警告:Oracle监听器IP冲突(oracle监听是ip)
- Linux实现静态IP设置(linux设置静态ip)
- 使用Linux实现代理IP网络加密保护(linux代理ip)
- Redis 接受访问限制:限制IP,提升安全性(redis限制ip)
- Linux下实现IP过滤功能的方法(linux ip过滤器)
- Linux下的IP SAN技术:实现无限可能(ip san linux)
- 基于Redis的IP访问限制实现(redis限制ip访问)
- ASP网页MySQL注入及防御研究(asp页面mysql注入)
- 用ASP编写MySQL数据库程序简单又高效(asp使用mysql代码)
- 局域网中架设本地Redis IP解决方案(本地redis ip)
- 基于Redis的分布式IP锁(分布式锁redis ip)
- Oracle 数据库使用IP连接实现快捷访问(oracle使用ip连接)
- Redis 远程IP连接实现方式研究(redis远程ip连接)
- Oracle IP设置保障网络安全的关键步骤(oracle ip设置)
- Redis集群IP实现快速获取(redis获取集群ip)
- asp经典入门教程在ASP中使用SQL语句
- asp实现检查ip地址是否为内网或者私有ip地址的代码分享