ASP implementation limits IP or IP segment access to site code

Source: Internet
Author: User
The code is as follows Copy Code

<%
"Get the address of the visitor
Ip=request.servervariables ("REMOTE_ADDR")
' The allowed IP address segment is 10.0.0.0~10.68.63.255
allowip1= "10.0.0.0"
Allowip2= "10.68.10.71"
Response.writecheckip (IP,ALLOWIP1,ALLOWIP2)
Functioncheckip (IP,ALLOWIP1,ALLOWIP2)
Dimcheck (4)
Checkip=false
Ipstr=split (IP, ".")
Allow1=split (Allowip1, ".")
Allow2=split (ALLOWIP2, ".")
Ifcint (Allow1 (0)) >cint (allow2 (0)) then ' to determine if the IP address segment is legitimate
Response.Write "No Access"
Exitfunction
endif
Fori=0toubound (IPSTR)
Ifcint (Allow1 (i)) <cint (Allow2 (i)) then
Ifcint (Allow1 (i)) =cint (Ipstr (i)) then
Check (i) =true
Checkip=true
Exitfor
Else
Ifcint (Ipstr (i)) <cint (Allow2 (i)) then
Check (i) =true
Checkip=true
Exitfor
Else
Ifcint (Ipstr (i)) >cint (Allow2 (i)) then
Check (i) =false
Checkip=false
Exitfor
Else
Check (i) =true
Checkip=true
endif
endif
endif
Else
Ifcint (Allow1 (i)) >cint (Ipstr (i)) Orcint (Allow1 (i)) <cint (Ipstr (i)) then
Check (i) =false
Checkip=false
Ifi<>ubound (IPSTR) Then
Exitfor
endif
Else
Check (i) =true
endif
endif
Next
if (check (0) =trueandcheck (1) =trueandcheck (2) =trueandcheck (3) =false) and (CInt (Allow2 (2)) >cint (IPSTR (2)) Then
Checkip=true
endif
Endfunction
%>

Here we put the code in the Index.asp file.

The code is as follows Copy Code
<%
A collection of masked IP addresses (segments) with an asterisk of wildcard characters, usually stored in a configuration file.
Const Badipgroup = "192.168.1.*|202.68.*.*|*.12.55.34|185.*.96.24|127.*.0.1|192.168.0.1"
If Isforbidip (badipgroup) = True Then
Response.Write (GetIP & "IP address No Access")
Response.End ()
End If
' Parameter Vbadip: IP segment to be screened, set of IP addresses, separate multiple IP addresses by | symbol (segment)
' Returns bool:true User IP in the masked range, False conversely
Function Isforbidip (VBADIP)
Dim counter, Arrippart, Arrbadip, Arrbadippart, I, J
Arrbadip = Split (Vbadip, "|")
Arrippart = Split (GetIP (), ".")
For i = 0 to UBound (ARRBADIP)
Counter = 0
Arrbadippart = Split (Arrbadip (i), ".")
For j = 0 to UBound (arrippart)
If (Arrbadippart (j)) = "*" or CStr (Arrippart (j)) = CStr (Arrbadippart (j)) Then
Counter = counter + 1
End If
Next
If counter = 4 Then
Isforbidip = True
Exit Function
End If
Next
Isforbidip = False
End Function
"Return the client IP address
Function GetIP ()
Dim IP
IP = Request.ServerVariables ("Http_x_forwarded_for")
If IP = "" Then IP = Request.ServerVariables ("REMOTE_ADDR")
GetIP = IP
End Function
%>

So again to visit the IP we just restricted try it's not going to work.

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.