频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

ip范围限制函数

来源: 作者: 出处:巧巧读书 2006-10-08 进入讨论组
大家如果还有好的建议算法,就联系我!!:)

'******************************
'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,".&收藏地址:http://www.qqread.com/asp/2006/10/b225541.html进入讨论组讨论。
收藏此文】【 】【打印】【关闭
较早的文章:Internet Information Server 错误代码

较新的文章:IP库-2
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
最新论坛文章
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章