一聚教程网:一个值得你收藏的教程网站

热门教程

检测IP网段

时间:2022-07-02 23:11:59 编辑:袖梨 来源:一聚教程网

先做取出第三段的数字 做比较不就行了

试试ip2long


echo ip2long('192.168.0.1')>= ip2long('192.168.0.61') && ip2long('192.168.0.61')>= ip2long('192.168.0.255');

方法二

'IP(段)检测
'sLockIp为禁止的IP(或IP段),多个用任意分隔符隔开就行了
'sUserIp为待检测的IP
Function SenFe_CheckIp(sLockIp, sUserIp)
    Dim aUserIp
    SenFe_CheckIp = True
    aUserIp = Split(sUserIp, ".")
    If SenFe_RegExpTest(sLockIp, Replace(sUserIp, ".", ".")) Then
        'Response.Write sUserIp & "禁止访问"
        SenFe_CheckIp = False
        Exit Function
    End If
    If SenFe_RegExpTest(sLockIp, aUserIp(0) & "(.(*|d+)){3,}") Then
        'Response.Write aUserIp(0) & ".*.*.*禁止访问"
        SenFe_CheckIp = False
        Exit Function
    End If
    If SenFe_RegExpTest(sLockIp, aUserIp(0) & "." & aUserIp(1) & "(.(*|d+)){2,}") Then
        'Response.Write aUserIp(0) & "." & aUserIp(1) & ".*.*禁止访问"
        SenFe_CheckIp = False
        Exit Function
    End If
    If SenFe_RegExpTest(sLockIp, aUserIp(0) & "." & aUserIp(1) & "." & aUserIp(2) & ".(*|d+)") Then
        'Response.Write aUserIp(0) & "." & aUserIp(1) & "." & aUserIp(2) & ".*禁止访问"
        SenFe_CheckIp = False
        Exit Function
    End If
End Function
Function SenFe_RegExpTest(sContent,sPatrn)
    Dim oTempReg : Set oTempReg = New RegExp
    With oTempReg
        .IgnoreCase = True
        .Global = True
        .Pattern = sPatrn
        SenFe_RegExpTest = .Test(sContent)
    End With
    Set TempReg = Nothing
End Function

热门栏目