Simple code IP address protected by ASP for Web pages

Source: Internet
Author: User
Tags servervariables microsoft frontpage

Use the servervariables attribute of the request object to obtain the value of the environment variable. The syntax used is: request. servervariables (variable), "variable" indicates the name of the environment variable, such as the server host name and web server software name. If "variable" is "remote_addr", it indicates the visitor's IP address, it can be used to filter IP addresses.

SourceProgram(File Name: Demo. asp)

<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb_2312-80">
<Meta name = "generator" content = "Microsoft FrontPage express 2.0">

<Style>
<! --
. As {Line-Height: 15px; font-size: 9pt}
A: hover {color: RGB (0,51, 240); text-Decoration: underline}
. P9 {font-family: ""; font-size: 9pt; line-Height: 15pt}
. P12 {font-family: ""; font-size: 12pt; line-Height: 18pt}
A: link {text-Decoration: none ;}
A: visited {text-Decoration: none ;}
A: hover {text-Decoration: underline; font-size: 125%; color: Blue}
-->
</Style>
<Title> ASP page firewall function demonstration </title>
</Head>

<Body background##back.jpg ">
<%
'Use request. servervariables ("remote_addr") to obtain the IP address and save it in the rip variable.
Rip = request. servervariables ("remote_addr ")
Strip = CSTR (RIP)
'Obtain the value of the third segment of the IP address and save it to strip.

For I = 1 to 2
Strip = right (strip, Len (strip)-instr (1, strip, ".")
Next

Strip = left (strip, instr (1, strip, ".")-1)
'The IP address validity test and password verification, including two aspects:
'Verification is performed if the IP address meets the requirements. If the IP address does not match the requirements, check whether the entered password is correct (the password here is "asp ")
If (left (RIP, 5) <> "127.1" or strip <"1" or strip> "50") and request ("passwd") <> "asp" then
%>
<P> <font color = "# ff0000"> sorry, your IP address is <% = rip %>. The IP address that can be accessed on this page is 127.1.1. * To 127.1.50. * If you are a user on the Intranet, make sure your browser does not use a proxy! <Br> </font> </P>
<Form action = "demo. asp" method = "Post" id = form1 name = form1>
<P> enter the access password: <input type = "password" name = "passwd"> <input type = "Submit" value = "OK" name = "B1">;
</P>
</Form>
<% Else %>
'The pages accessible to legal users can add any information here
Congratulations! You have successfully passed the page security certification and can directly use the resources on this site!
<% End if %>
</Body>
</Html>

In actual use, you only need to slightly modify the above program (such as the IP address and other information), of course, this is only implemented in a page security protection function, if a website has multiple pages, you can set a session variable to flag the user for judgment on the following page.

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.