推荐的用Asp实现屏蔽IP地址访问的代码
程序员文章站
2022-05-18 11:45:56
by zkxp 2/15/2006 http://zkxp.cnblogs.com ‘受屏蔽ip地址(段)集合,星号为通配符,通常保存于配置文...
by zkxp 2/15/2006 http://zkxp.cnblogs.com
‘受屏蔽ip地址(段)集合,星号为通配符,通常保存于配置文件中。
<%
const badipgroup = "220.200.59.136|220.205.168.141"
if isforbidip(badipgroup) = true then
response.write(getuserip &"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(getuserip(), ".")
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 getuserip()
dim ip
ip = request.servervariables("http_x_forwarded_for")
if ip = "" then ip = request.servervariables("remote_addr")
getuserip = ip
end function
%>
‘受屏蔽ip地址(段)集合,星号为通配符,通常保存于配置文件中。
<%
const badipgroup = "220.200.59.136|220.205.168.141"
if isforbidip(badipgroup) = true then
response.write(getuserip &"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(getuserip(), ".")
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 getuserip()
dim ip
ip = request.servervariables("http_x_forwarded_for")
if ip = "" then ip = request.servervariables("remote_addr")
getuserip = ip
end function
%>