Friends who need it can refer to the code for prohibiting specified IPs and allowing only specified IPs to access the website through ASP. 1. Prohibit designated IP defense websites and perform corresponding operations:
Copy the code code as follows:
<%
Dim IP,IPString,VisitIP
'Set IP address, separated by |
IPString=|192.168.0.42|192.168.0.43|
'Get IP address
IP = Request.ServerVariables(HTTP_X_FORWARDED_FOR)
If IP = Then
IP = Request.ServerVariables(REMOTE_ADDR)
End If
VisitIP=|&IP&|
If instr(1,IPString,VisitIP)>0 Then
'Perform corresponding operations for banned IPs
Response.write Your IP is prohibited from accessing
response.end
End If
%>
2. Modify the code to allow only designated IP defense websites, and perform the corresponding operations:
Copy the code code as follows:
<%
Dim IP,IPString,VisitIP
'Set the IP address, separated by |
IPString=|192.168.0.42|192.168.0.42|
'Get IP address
IP = Request.ServerVariables(HTTP_X_FORWARDED_FOR)
If IP = Then
IP = Request.ServerVariables(REMOTE_ADDR)
End If
VisitIP=|&IP&|
If instr(1,IPString,VisitIP)>0 Then
'The corresponding IP performs the corresponding operation
Response.write Your IP can access
else
'Perform corresponding operations for non-compliant IPs
Response.write Your IP is prohibited from accessing
response.end
End If
%>
3. Usage in practical applications:
Then save the above code as an IP.asp file, and then use the following method to add the following code to the asp program page.
<!-- #include file=IP.asp -->