ASP對網頁進行保護的簡單代碼 ip
2024-05-04 11:01:28
供稿:網友
要使用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>