The limitation of IP function in ASP

Source: Internet
Author: User
Tags exit end net range split
function | detailed ' ******************************
' Function Checkip (CINPUT_IP,CBOUND_IP)
' Created by Qqdao, Qqdao@263.net 2001/11/28
' Description: First you need to be based on the number loop, and then determine if there is a "-", if there is a split processing, and finally determine whether in the scope
' Parameters: Cinput_ip, Ip on behalf of check
' Cbound_ip, given a range of formats, a single IP, and range IP, the range IP last used "-" split, if it is "*" must be put to the last
' After each range add ': ALLOW ' indicates permission to login, add ": Refuse" indicates refusal to log in. multiple ranges with ";" Separated
' such as 192.168.1*.*:allow;192.168.1.1:allow;192.168.1.1-10:refuse '
' Return value: True/false
' Update: 2001/12/05 support Allow,refuse Support ' * ', do not want to? Support, because and * almost
'******************************
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 "just refused.
Ctemp_ip = Left (Csingle_ip (i), InStr (Csingle_ip (i), ":")-1)

If Instr (ctemp_ip, "*") <> 0 Then "is wide range
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 "allow

Ctemp_ip = Left (Csingle_ip (i), InStr (Csingle_ip (i), ":")-1)

If Instr (ctemp_ip, "*") <> 0 Then "is wide range
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
' Reference moving network IP algorithm '
' Parameter: CIP IP address
' Return value: value after conversion
'******************************
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, ".") Cip,instr -1)
Cip_temp=mid (CIp, ".") Cip,instr +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

Else
Ip2str=cint (STR1) *256*256*256+cint (str2) *256*256+cint (STR3) *256+cint (STR4)-1
End If

End Function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.