Asp限制IP訪問(wèn) 阻止某一個(gè)IP段禁止訪問(wèn)本站的代碼
<%
''獲取訪問(wèn)者的地址
ip=Request.ServerVariables("REMOTE_ADDR")
''允許的IP地址段為10.0.0.0~10.68.63.255
allowip1="10.0.0.0"
allowip2="10.68.10.71"
response.writecheckip(ip,allowip1,allowip2)
functioncheckip(ip,allowip1,allowip2)
dimcheck(4)
checkip=false
ipstr=split(ip,".")
allow1=split(allowip1,".")
allow2=split(allowip2,".")
ifcint(allow1(0))>cint(allow2(0))then''判斷IP地址段是否合法
response.write"禁止訪問(wèn)"
exitfunction
endif
fori=0toubound(ipstr)
ifcint(allow1(i))<cint(allow2(i))then
ifcint(allow1(i))=cint(ipstr(i))then
check(i)=true
checkip=true
exitfor
else
ifcint(ipstr(i))<cint(allow2(i))then
check(i)=true
checkip=true
exitfor
else
ifcint(ipstr(i))>cint(allow2(i))then
check(i)=false
checkip=false
exitfor
else
check(i)=true
checkip=true
endif
endif
endif
else
ifcint(allow1(i))>cint(ipstr(i))orcint(allow1(i))<cint(ipstr(i))then
check(i)=false
checkip=false
ifi<>ubound(ipstr)then
exitfor
endif
else
check(i)=true
endif
endif
next
if(check(0)=trueandcheck(1)=trueandcheck(2)=trueandcheck(3)=false)and(cint(allow2(2))>cint(ipstr(2)))then
checkip=true
endif
endfunction
%>
把以下代碼加入到你的ASP頁(yè)面就可以測(cè)試到效果了:
<%
'受屏蔽IP地址(段)集合,星號(hào)為通配符,通常保存于配置文件中。
Const BadIPGroup = "192.168.1.*|202.68.*.*|*.12.55.34|185.*.96.24|127.*.0.1|192.168.0.1"
If IsForbidIP(BadIPGroup) = True Then
Response.Write(GetIP &"IP地址禁止訪問(wèn)")
Response.End()
End If
'參數(shù)vBadIP:要屏蔽的IP段,IP地址集合,用|符號(hào)分隔多個(gè)IP地址(段)
'返回Bool:True用戶IP在被屏蔽范圍,F(xiàn)alse 反之
Function IsForbidIP(vBadIP)
Dim counter, arrIPPart, arrBadIP, arrBadIPPart, i, j
arrBadIP = Split(vBadIP, "|")
arrIPPart = Split(GetIP(), ".")
For i = 0 To UBound(arrBadIP)
counter = 0
arrBadIPPart = Split(arrBadIP(i), ".")
For j = 0 To UBound(arrIPPart)
If(arrBadIPPart(j)) = "*" or Cstr(arrIPPart(j)) = Cstr(arrBadIPPart(j)) Then
counter = counter + 1
End If
Next
If counter = 4 Then
IsForbidIP = True
Exit Function
End If
Next
IsForbidIP = False
End Function
''返回客戶IP地址
Function GetIP()
Dim IP
IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If IP = "" Then IP = Request.ServerVariables("REMOTE_ADDR")
GetIP = IP
End Function
%>
這樣就可以限制網(wǎng)站訪問(wèn)的IP段了,你可以根據(jù)地區(qū)的IP段來(lái)設(shè)置。
我就是用這個(gè)方法防止外地用戶使用流氓軟件惡意到我網(wǎng)站發(fā)布信息的!
- ASP.net做的IP訪問(wèn)限制
- 用ASP代碼實(shí)現(xiàn)對(duì)IP的訪問(wèn)限制的代碼
- Asp下實(shí)現(xiàn)限制IP訪問(wèn)的程序代碼
- 用asp腳本實(shí)現(xiàn)限制IP訪問(wèn)
- 推薦的用Asp實(shí)現(xiàn)屏蔽IP地址訪問(wèn)的代碼
- ADSI+ASP添加IP到IIS禁止訪問(wèn)列表中
- 記錄游客頁(yè)面訪問(wèn)IP的簡(jiǎn)易實(shí)現(xiàn)代碼 (asp.net+txt)
- 通過(guò)ASP禁止指定IP和只允許指定IP訪問(wèn)網(wǎng)站的代碼
- asp實(shí)現(xiàn)限制一個(gè)ip只能訪問(wèn)一次的方法
相關(guān)文章
asp中使用mysql數(shù)據(jù)庫(kù)的注意實(shí)現(xiàn)
2008-01-01Ajax跨域代理訪問(wèn)網(wǎng)絡(luò)資源的實(shí)現(xiàn)代碼
解決Ajax跨域訪問(wèn)報(bào)“沒(méi)有權(quán)限”的錯(cuò)誤。需要的朋友可以參考下。2011-03-03用asp實(shí)現(xiàn)網(wǎng)址和郵件地址的轉(zhuǎn)換函數(shù)
用asp實(shí)現(xiàn)網(wǎng)址和郵件地址的轉(zhuǎn)換函數(shù)...2007-11-11關(guān)于ASP循環(huán)表格的問(wèn)題之解答[比較詳細(xì)]
在很多時(shí)候,我們采用原始的方法來(lái)解決一行內(nèi)循環(huán)3張圖片,如果上傳者只上傳了2張圖片,那么2張圖片間的距離會(huì)很大,因?yàn)槿鄙倭艘粋€(gè)<td> </td>.2008-11-11asp 動(dòng)態(tài)數(shù)組 提供Add、Insert、Remove、RemoveAt、Search等方法。
asp動(dòng)態(tài)數(shù)組,提供Add、Insert、Remove、RemoveAt、Search等方法??梢栽跀?shù)組中存儲(chǔ)對(duì)象不考慮效率問(wèn)題2009-10-10可以應(yīng)用到馬克斯電影站生成Rss Feed的代碼
前段時(shí)間為了給本人的電影站增加Rss訂閱功能,動(dòng)手寫了個(gè)動(dòng)態(tài)生成Rss Feed的ASP代碼,沒(méi)法上傳附件,就直接貼代碼吧,反正也不長(zhǎng),用馬克斯做電影站的朋友直接拿去用吧,其它類型的站點(diǎn)修改一下也能用。生成的Rss Feed采用UTF-8編碼,經(jīng)過(guò)feedvalidator.org校驗(yàn),兼容Rss 2.0和Atom。2008-03-03ASP基礎(chǔ)入門第四篇(腳本變量、函數(shù)、過(guò)程和條件語(yǔ)句)
大家在學(xué)習(xí)了腳本語(yǔ)言 VBScript 的變量、常量和過(guò)程的基本概念后,本期將繼續(xù)向各位介紹 VBScript 的函數(shù)和語(yǔ)法。2015-10-10ASP移動(dòng)文件函數(shù)movefile權(quán)限不足的替代方法
這篇文章主要介紹了ASP移動(dòng)文件函數(shù)movefile權(quán)限不足的替代方法,本文先是介紹了一個(gè)替代方法,后又找出了實(shí)際原因,需要的朋友可以參考下2014-07-07