asp指定ip訪問
A. asp怎麼限制只允許國內ip訪問
http://arthorzhou888.blog.163.com/blog/static/313091532007624112841640/
把這個寫入資料庫 然後加入到conn.asp文件裡面 很簡單
ip=Request.ServerVariables("REMOTE_ADDR")
''允許的IP地址段為10.0.0.0~10.50.50.255
allowip1="10.0.0.0"
allowip2="10.50.10.70"
response.write checkip(ip,allowip1,allowip2)
function checkip(ip,allowip1,allowip2)
dim check(4)
checkip=false
ipstr=split(ip,".")
allow1=split(allowip1,".")
allow2=split(allowip2,".")
if cint(allow1(0))>cint(allow2(0)) then ''判斷IP地址段是否合*
response.write "禁止訪問"
exit function
end if
B. ASP限制IP訪問
1.ASP限制IP訪問代碼
<%
''獲取訪問者的地址
ip=Request.ServerVariables("REMOTE_ADDR")
''允許的IP地址段為10.0.0.0~10.50.50.255
allowip1="10.0.0.0"
allowip2="10.50.10.70"
response.write checkip(ip,allowip1,allowip2)
function checkip(ip,allowip1,allowip2)
dim check(4)
checkip=false
ipstr=split(ip,".")
allow1=split(allowip1,".")
allow2=split(allowip2,".")
if cint(allow1(0))>cint(allow2(0)) then ''判斷IP地址段是否合*
response.write "禁止訪問"
exit function
end if
for i=0 to ubound(ipstr)
if cint(allow1(i))<cint(allow2(i)) then
if cint(allow1(i))=cint(ipstr(i)) then
check(i)=true
checkip=true
exit for
else
if cint(ipstr(i))<cint(allow2(i)) then
check(i)=true
checkip=true
exit for
else
if cint(ipstr(i))>cint(allow2(i)) then
check(i)=false
checkip=false
exit for
else
check(i)=true
checkip=true
end if
end if
end if
else
if cint(allow1(i))>cint(ipstr(i)) or cint(allow1(i))<cint(ipstr(i)) then
check(i)=false
checkip=false
if i<>ubound(ipstr) then
exit for
end if
else
check(i)=true
end if
end if
next
if (check(0)=true and check(1)=true and check(2)=true and check(3)=false) and (cint(allow2(2))>cint(ipstr(2))) then
checkip=true
end if
end function
%>
2.用戶IP限制
<%'用戶IP限制
function LockIP(sip)
dim str1,str2,str3,str4
dim num
LockIP=false
if isnumeric(left(sip,2)) then
str1=left(sip,instr(sip,".")-1)
sip=mid(sip,instr(sip,".")+1)
str2=left(sip,instr(sip,".")-1)
sip=mid(sip,instr(sip,".")+1)
str3=left(sip,instr(sip,".")-1)
str4=mid(sip,instr(sip,".")+1)
if isNumeric(str1)=0 or isNumeric(str2)=0 or isNumeric(str3)=0 or isNumeric(str4)=0 then
else
num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1
sql="select count(*) from LockIP where ip1 <="&num&" and ip2 >="&num&""
set rs_ip=conn.execute(sql)
if rs_ip(0)>0 then
LockIP=true
end if
set rs_ip=nothing
end if
end if
end function%>
<%if LockIP(Request.ServerVariables("REMOTE_ADDR")) then
response.write "<script>alert('您的IP:"&request.servervariables("remote_addr")&"已經被限制不能訪問,請和管理員聯系');location.href='about:blank'</script><script>window.close();</script>"
response.end
end if
%>
<%
noip=Request.Servervariables("HTTP_X_FORWARDED_FOR")
If noip="" Then noip=Request.Servervariables("REMOTE_ADDR")
set rst11=server.createobject("adodb.recordset")
sql="select * from fuck where userip='"&noip&"'"
rst11.open sql,conn,1,1
if not rst11.eof and not rst11.bof then
response.write "<script>alert('您的IP:"&request.servervariables("remote_addr")&"已經被限制不能訪問,請和管理員聯系');location.href='about:blank'</script><script>window.close();</script>"
response.end
end if
%>
C. 我用asp剛做好一個網頁,怎樣讓別人通過我的ip訪問我的網頁
第一步:設置你的本機ip,地址為你外網的地址(ip138查詢)
第二步:要把你iis裡面的默認訪問地址改為你的本機(也就是第一步的ip)ip地址(第一步成功後下拉就會出現)
我這里沒裝iis不能給你截圖,不好意思 ~_~!
D. asp頁面如何設置只對指定IP段開放許可權
可以通過兩種方式實現:
1、通過設置IIS的許可權來限制外網訪問,如圖
2、通過在asp中寫代碼控制,網路一下就有相關代碼
E. asp學習:asp如何只允許某些IP訪問
先要得到客戶端的IP地址,然後進行判斷,例: ip=request.servervariables("Remote_Addr") if Left(ip,8)="192.168." then ... else ... end if
滿意請採納
F. 修改asp限制IP訪問
參考下面的屏蔽ip段的代碼<%
'受屏蔽IP地址(段)集合,星號為通配符,通常保存於配置文件中。
ConstBadIPGroup="192.168.1.*|202.68.*.*|*.12.55.34|185.*.96.24|127.*.0.1|192.168.0.1"
IfIsForbidIP(BadIPGroup)=TrueThen
Response.Write(GetIP&"IP地址禁止訪問")
Response.End()
EndIf
'參數vBadIP:要屏蔽的IP段,IP地址集合,用|符號分隔多個IP地址(段)
'返回Bool:True用戶IP在被屏蔽范圍,False反之
FunctionIsForbidIP(vBadIP)
Dimcounter,arrIPPart,arrBadIP,arrBadIPPart,i,j
arrBadIP=Split(vBadIP,"|")
arrIPPart=Split(GetIP(),".")
Fori=0ToUBound(arrBadIP)
counter=0
arrBadIPPart=Split(arrBadIP(i),".")
Forj=0ToUBound(arrIPPart)
If(arrBadIPPart(j))="*"orCstr(arrIPPart(j))=Cstr(arrBadIPPart(j))Then
counter=counter+1
EndIf
Next
Ifcounter=4Then
IsForbidIP=True
ExitFunction
EndIf
Next
IsForbidIP=False
EndFunction
'返回客戶IP地址
FunctionGetIP()
DimIP
IP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
IfIP=""ThenIP=Request.ServerVariables("REMOTE_ADDR")
GetIP=IP
EndFunction
%>
G. ASP如何實現限制區域地區IP訪問,定向IP訪問
要使用request對象
的ServerVariables屬性,通過它來獲得環境變數的值。使用的語法為:Request.ServerVariables(variable),variable表示環境變數的名稱,如伺服器主機名稱、Web伺服器軟體名等等,若variable為REMOTE_ADDR則表示訪問者的IP地址,通過它就可以實現IP地址的過濾。
源程序如下:(文件名:demo.ASP)<html><head>
<metahttp-equiv=Content-Typecontent=text/html;charset=gb_2312-80><metaname=GENERATORcontent=MicrosoftFrontPageExpress2.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><bodybackground=back.jpg><%′使用Request.ServerVariables(REMOTE_ADDR)得到IP地址並保存在變數rip中rip=Request
.ServerVariables(REMOTE_ADDR)strip=cstr(rip)′取得IP地址第三個段的值並保存到strip中fori=1to2strip=right(strip,len(strip)-instr(1,strip,.))nextstrip=left(strip,instr(1,strip,.)-1)
′IP地址有效性檢驗及密碼驗證,包括兩方面的內容:
′如果IP地址符合則通過驗證;如果IP地址不符合則檢驗輸入的密碼是否正確(此處密碼為asp)
if(left(rip,5)<>127.1orstrip<1orstrip>50)andrequest(Passwd)<>aspthen%><p><fontcolor=#FF0000>對不起,你的IP是<%=rip%>,本頁面可以訪問的IP是127.1.1.*到127.1.50.*之間,如果你是本單位內部網的用戶,請確認你的瀏覽器沒有使用代理!<BR></font></p><formaction=demo.aspmethod=POSTid=form1name=form1><p>請輸入訪問密碼:<inputtype=passwordname=Passwd><inputtype=submitvalue=確認name=B1>;</p></form>
<%else%>
′合法用戶可以訪問的頁面,在此可以加入任何信息
祝賀您,您已經順利通過了頁面的安全認證,可以直接使用本站點的資源!
<%endif%>
</body>
H. asp允許資料庫內IP訪問
If Not (IpRS.bof or IpRS.eof) Then
WhyIpLock=split(IpRS("iplock"),"|")
Response.Write"<BR><ol>你使用的IP段或IP地址已被封鎖"
Response.Write"<Li>封鎖原因:"&WhyIpLock(1)
Response.Write"<LI>封鎖時間:"&WhyIpLock(0)
Response.Write"<LI>請與管理員聯系</ol>"
Response.End
End If
====》
If IpRS.eof Then
Response.Write"<BR><ol>你使用的IP段或IP地址未被授權訪問!"
Response.Write"<LI>請與管理員聯系</ol>"
Response.End
End If
後台管理處小心些,如果你是固定ip的話好說,如果是動態上網別哪天自己也無法登陸就必須手動修改資料庫了。
I. asp如何在網頁中通過識別IP地址限制訪問網頁的部分頁面
先獲取來訪者的IP,經判斷後轉向頁面地址,IP判斷一般有兩個方向:
1、是以區域IP判斷,禁止某一區域的IP地址訪問,這個要用到IP庫
2、是以特定的IP列表禁止訪問,這個要在你的資料庫中添加有指定的IP列表。
符合上面2個條件的來訪者將被轉向到其他頁面,原理大概是這樣,代碼自己想想吧。
J. 如何指定某幾個IP可以訪問特定目錄下的ASP的問題
弄個表來存下IP,那些文件里引用一段代碼是判定有沒有這些IP的,沒有就跳到別的頁面,有才可以訪問不就行了....很簡單的.