主要使用request对象的servervariables属性,通过它来获得环境变量的值。使用的语法为:request.servervariables(variable),“variable”表示环境变量的名称,如服务器主机名称、web服务器软件名等等,若“variable”为“remote_addr”则表示访问者的ip地址,通过它就可以实现ip地址的过滤。
源程序如下:(文件名: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页面防火墙功能演示</title>
</head>
<body background=“back.jpg”>
<%
′使用request.servervariables(“remote_addr”)得到ip地址并保存在变量rip中
rip=request.servervariables(“remote_addr”)
strip=cstr(rip)
′取得ip地址第三个段的值并保存到strip中
for i=1 to 2
strip=right(strip,len(strip)-instr(1,strip,“.”))
next
strip=left(strip,instr(1,strip,“.”)-1)
′ip地址有效性检验及密码验证,包括两方面的内容:
′如果ip地址符合则通过验证;如果ip地址不符合则检验输入的密码是否正确(此处密码为“asp”)
if (left(rip,5) <> “127.1” or strip<“1” or strip>“50”) and request(“passwd”)<>“asp” then
%>
<p><font color=“#ff0000”>对不起,你的ip是<%=rip%>,本页面可以访问的ip是127.1.1.*到127.1.50.*之间,如果你是本单位内部网的用户,请确认你的浏览器没有使用代理!<br></font></p>
<form action=“demo.asp” method=“post” id=form1 name=form1>
<p>请输入访问密码:<input type=“password” name=“passwd” > <input type=“submit” value=“确认” name=“b1”>;
</p>
</form>
<%else %>
′合法用户可以访问的页面,在此可以加入任何信息
祝贺您,您已经顺利通过了页面的安全认证,可以直接使用本站点的资源!
<%end if%>
</body>
</html>
实际使用只要稍微修改上面的程序(如ip地址等信息)就可以了,当然这只是在一个页面中实现了安全防范功能,如果一个网站有多个页面的话,可以设置一个session变量来对用户进行标志,以在后面的页面中进行判断。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器