Use ASP to prohibit the specified IP address and the code that only allows the specified IP address to access the website

Source: Internet
Author: User
Tags servervariables

1. Disable the specified IP address to prevent website attacks and perform the following operations: Copy codeThe Code is as follows: <%
Dim IP, IPString, VisitIP
'Set IP addresses 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
'The prohibited IP address is allowed to perform the corresponding operation
Response. write "Access prohibited from your IP address"
Response. end
End If
%>

2. modify the code to only allow the specified IP address to defend against website attacks and perform the following operations:Copy codeThe Code is as follows: <%
Dim IP, IPString, VisitIP
'Set IP addresses 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
'Operation is performed on the correct IP address.
Response. write your IP address can access"
Else
'The non-conforming IP address performs the corresponding operation
Response. write "Access prohibited from your IP address"
Response. end
End If
%>

Iii. Usage in practical application:
Save the above Code as an IP. asp file, and then add the following code to the asp program page using the following method:
<! -- # Include file = "IP. asp" -->

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.