国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

Asp限制IP訪問 阻止某一個IP段禁止訪問本站的代碼

2024-05-04 10:59:54
字體:
供稿:網(wǎng)友
復(fù)制代碼 代碼如下:
<%
''獲取訪問者的地址
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"禁止訪問"
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頁面就可以測試到效果了:
復(fù)制代碼 代碼如下:
<%
'受屏蔽IP地址(段)集合,星號為通配符,通常保存于配置文件中。
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地址禁止訪問")
Response.End()
End If
'參數(shù)vBadIP:要屏蔽的IP段,IP地址集合,用|符號分隔多個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)站訪問的IP段了,你可以根據(jù)地區(qū)的IP段來設(shè)置。
  我就是用這個方法防止外地用戶使用流氓軟件惡意到我網(wǎng)站發(fā)布信息的!

您可能感興趣的文章:

ASP.net做的IP訪問限制用ASP代碼實現(xiàn)對IP的訪問限制的代碼Asp下實現(xiàn)限制IP訪問的程序代碼用asp腳本實現(xiàn)限制IP訪問推薦的用Asp實現(xiàn)屏蔽IP地址訪問的代碼ADSI+ASP添加IP到IIS禁止訪問列表中記錄游客頁面訪問IP的簡易實現(xiàn)代碼 (asp.net+txt)通過ASP禁止指定IP和只允許指定IP訪問網(wǎng)站的代碼asp實現(xiàn)限制一個ip只能訪問一次的方法
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 晋城| 夹江县| 军事| 喀什市| 佛学| 潜山县| 德钦县| 闽侯县| 陕西省| 基隆市| 鄢陵县| 罗源县| 黄山市| 措勤县| 阳泉市| 天长市| 同江市| 涡阳县| 金阳县| 仙桃市| 德庆县| 富顺县| 济南市| 鄂州市| 内江市| 正镶白旗| 南投县| 天长市| 和平县| 房产| 抚远县| 溧水县| 博兴县| 元阳县| 高台县| 古蔺县| 育儿| 永安市| 潼关县| 禄劝| 松潘县|