限制ip访问网站问题

jeffrey119 2012-07-25 04:28:57
在主页的开始加入如下一段后,但我拿ip是192.168.1.206的机子去访问为什么返回的值是true呢??求高手


代码如下:


<%
dim ip,allow1,allow2,allowip1,allowip2,ipstr,i

''获取访问者的地址
ip=Request.ServerVariables("REMOTE_ADDR")
''允许的IP地址段为192.168.1.207~192.168.1.255
allowip1="192.168.1.207"
allowip2="192.168.1.255"
response.write checkip(ip,allowip1,allowip2)
function checkip(ip,allowip1,allowip2)
dimcheck(4)
checkip=false
ipstr=split(ip,".")
allow1=split(allowip1,".")
allow2=split(allowip2,".")
if cint(allow1(0))>cint(allow2(0))then''判断IP地址段是否合法
response.write"禁止访问"
exit function
end if
for i=0 to ubound(ipstr)
if cint(allow1(i))<cint(allow2(i)) then
if cint(allow1(i))=cint(ipstr(i)) then
check(i)=true
checkip=true
exit for
else
if cint(ipstr(i))<cint(allow2(i)) then
check(i)=true
checkip=true
exit for
else
if cint(ipstr(i))>cint(allow2(i)) then
check(i)=false
checkip=false
exit for
else
check(i)=true
checkip=true
end if
end if
end if
else
if cint(allow1(i))>cint(ipstr(i)) or cint(allow1(i))<cint(ipstr(i)) then
check(i)=false
checkip=false
if i<>ubound(ipstr) then
exit for
end if
else
check(i)=true
end if
end if
next
if (check(0)=true and check(1)=true and check(2)=true and check(3)=false) and (cint(allow2(2))>cint(ipstr(2))) then
checkip=true
end if
end function
%>
...全文
229 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2012-07-25
  • 打赏
  • 举报
回复
晕。。你转换为数字后在比较不是更加简单??

function getipnum(ip)
arr=split(ip,".")
getipnum=256*256*256*cint(arr(0)) + 256*256*cint(arr(1)) + 256*cint(arr(2)) +cint(arr(3))'转换为数字
end function
function checkip(ip,ip1,ip2)
ip=getipnum(ip)
ip1=getipnum(ip1)
ip2=getipnum(ip2)
checkip=(ip>=ip1 and ip<=ip2) or (ip>=ip2 and ip<=ip1)
end function

response.write checkip("192.168.1.206","192.168.1.207","192.168.1.255")''''''''
jeffrey119 2012-07-25
  • 打赏
  • 举报
回复
我在前面加了
dim ip,allow1,allow2,allowip1,allowip2,ipstr,i
就好了,但为什么返回的值是true呢

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧