麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > ASP > 正文

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

2024-05-04 11:07:21
字體:
來源:轉載
供稿:網友

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

經常有些地方性的B2B或者B2C網站到處都被批量發布好多垃圾信息,把我的解決辦法分享給大家

代碼如下:


<%
''獲取訪問者的地址
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頁面就可以測試到效果了:

 

復制代碼 代碼如下:

<%
'受屏蔽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
'參數vBadIP:要屏蔽的IP段,IP地址集合,用|符號分隔多個IP地址(段)
'返回Bool:True用戶IP在被屏蔽范圍,False 反之
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
%>


  這樣就可以限制網站訪問的IP段了,你可以根據地區的IP段來設置。

 

  我就是用這個方法防止外地用戶使用流氓軟件惡意到我網站發布信息的!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产91免费看| 亚洲一区二区观看播放 | 日韩美女电影 | 毛片在线免费播放 | 久久另类视频 | 亚洲精品 在线播放 | 午夜精品久久久久久久爽 | av懂色| 成人午夜在线免费观看 | 免费在线观看中文字幕 | 72pao成人国产永久免费视频 | 国产成人精品午夜 | 成人免费一区二区三区视频网站 | 美女性感毛片 | 日韩av在线资源 | 午夜视频观看 | 极色品影院 | 成人福利软件 | 久久久久97国产精 | 视频一区二区中文字幕 | a网在线| 国产日韩在线 | 成人在线视频精品 | 黄色毛片一级 | 97风流梦电影 | 国产成人精品二区 | 91成人在线免费观看 | 精品国产乱码久久久久久久 | 成人国产在线看 | 日本看片一区二区三区高清 | 国产午夜免费 | 成人做爰s片免费看网站 | 蜜桃视频在线播放 | 精品国产91久久久久久久 | 一区二区三视频 | 国产成人精品免费视频大全最热 | 中文字幕22页 | 国产啊v在线观看 | 国内精品久久久久久2021浪潮 | 一本一本久久a久久精品综合小说 | 99国语露脸久久精品国产ktv |