复制代码代码如下所示:
<
得到访客的地址
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 =分裂(IP,,)
allow1 =分裂(allowip1,,)
allow2 =分裂(allowip2,,)
Ifcint(allow1(0))> Cint(allow2(0))然后''determines是否是合法IP地址段
response.write 禁止访问
exitfunction
endif
因为= 0toubound(ipstr)
Ifcint(allow1(I))< Cint(allow2(I))然后
Ifcint(allow1(I))= Cint(ipstr(I))然后
检验(i)=真的
checkip =真
exitfor
其他的
Ifcint(ipstr(I))< Cint(allow2(I))然后
检验(i)=真的
checkip =真
exitfor
其他的
Ifcint(ipstr(I))> Cint(allow2(I))然后
检验(i)=假
checkip = false
exitfor
其他的
检验(i)=真的
checkip =真
endif
endif
endif
其他的
Ifcint(allow1(I))> Cint(ipstr(I))orcint(allow1(I))< Cint(ipstr(我))
检验(i)=假
checkip = false
IFI <> UBound(ipstr)然后
exitfor
endif
其他的
检验(i)=真的
endif
endif
下一个
如果(检查(0)(1)= = trueandcheck trueandcheck(2)= trueandcheck(3)= false)和(CINT(allow2(2))> Cint(ipstr(2)))然后
checkip =真
endif
endfunction
%>

在ASP页面中添加以下代码来测试效果:
复制代码代码如下所示:
<
屏蔽IP地址(段)集合,星号是通配符,通常保存在配置文件中。
const badipgroup =192.168.1.×| 202.68。*。* | *。12.55.34 | 185。*。96.24 | 127。*。0.1 | 192.168.0.1
如果IsForbidIP(badipgroup)=真
响应。写(getip IP地址禁止访问)
响应(完)
最后如果
参数vbadip:IP段屏蔽,IP地址设置为与|符号分隔多个IP地址(段)
返回bool:在屏蔽范围用户的真实IP,假亦然
函数的IsForbidIP(vbadip)
昏暗的柜台,arrippart,arrbadip,arrbadippart,I,J
arrbadip =分裂(vbadip,| )
arrippart =分裂(GetIP(),,)
For I = 0 To UBound (arrBadIP)
反= 0
arrbadippart =分裂(arrbadip(我),,)
J = 0,UBound(arrippart)
如果(arrbadippart(j))=*或Cstr(arrippart(j))= Cstr(arrbadippart(j))然后
计数器=计数器+ 1
最后如果
下一个
如果计数器= 4,那么
isforbidip =真
退出功能
最后如果
下一个
isforbidip = false
端功能
返回客户的IP地址
GetIP()函数
昏暗的IP
IP = request.servervariables(http_x_forwarded_for )
如果IP = 然后IP = request.servervariables(remote_addr )
getip = IP
端功能
%>

这可以限制站点访问的IP段,您可以根据该区域的IP部分设置它。
我用这种方法来防止本地用户使用流氓软件的信息发送到我的网站!