如何把访问权限限制在一定的ip范围内?

odie 2003-08-30 08:13:57
如何把访问权限限制在一定的ip范围内?
...全文
165 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tonglu 2003-08-30
  • 打赏
  • 举报
回复
'------------判断在IP段内一个IP是否为合法的函数----------------
function checkip(IpStart,IpEnd,Iptarget)
Array_Start=split(IpStart,".")
Array_End=split(IpEnd,".")
Array_Target=split(Iptarget,".")
dim isin
isin=1
haslarge=0

for i=0 to 2
if array_start(i)<array_end(i) then
haslarge=1
end if
next
if haslarge=1 then
aubound=255
else
aubound=array_end(3)
end if

for i=0 to 3
if i=3 then
if cint(Array_Target(i))>cint(aubound) or cint(Array_Target(i))<cint(Array_Start(i)) then
isin=isin*0
else
isin=isin*1
end if
else
if Array_Target(i)>Array_End(i) or Array_Target(i)<Array_Start(i) then
isin=isin*0
else
isin=isin*1
end if
end if
next

'------------------------数据库里只有对应一记录时适用-----------------
'if isin = 0 then
'Response.Write("<script language=javascript>alert('对不起!您的IP地址不在权限之类,系统将拒绝您的请求!');history.back()</script>")
'Response.End
'end if
'---------------------------------------------------------------------

checkip=isin
end function

'-------------------------调 用(数据库有多条记录)---------------------------
set rsd = conn.execute("select ip,ip1 from ip_rule where gid='"&newrs("lev")&"'")
'得到本机ip
localIP = Request.ServerVariables("LOCAL_ADDR")
dim temp
temp = 0
if not rsd.eof then
while not rsd.eof
if checkip(rsd("ip"),rsd("ip1"),localIP) then
temp = temp+1
end if
rsd.movenext
wend
rsd.close
set rsd = nothing
if temp=0 then
Response.Write("<script language=javascript>alert('对不起!您的IP地址不在权限之类,系统将拒绝您的请求!');history.back()</script>")
end if
end if


----说 明----

本函数适用判断一个IP地址(函数对应参数-->Iptarget)在一个自定义的IP地址段内是否合法
例:
ID IP IP1 GID
120 192.168.0.1 192.168.0.254 76
121 10.150.0.1 10.150.8.21 76
122 192.168.0.31 192.168.0.31 76
120 203.93.131.0 203.93.131.23 77
121 10.155.9.1 10.155.9.21 77
........

如果gid=76 那么合法IP地址为 192.168.0.1~~~~~192.168.0.254 和 10.150.0.1~~~~~~~~10.150.8.21内的所有IP地址
但是如果gid=77 那么这些IP地址都不合法了 合法的为203.93.131.0~~203.93.131.23和10.155.9.1~~10.155.9.21内的IP地址

如果数据库里只有对应的一条IP地址限定 就可以直接调用函数 并去掉函数体里的注释
如:
ID IP IP1 GID
120 192.168.0.1 192.168.0.254 76
121 10.150.0.1 10.150.8.21 77
122 192.168.0.31 192.168.0.31 78
.........

这样 就只需要直接调用函数 call checkip(rsd("ip"),rsd("ip1"),localIP)


----数据库字段说明-----
IP --> 开始IP 对应函数体类IpStart参数
IP1 --> 结束IP 对应函数体类IpEnd参数
ouyanggz 2003-08-30
  • 打赏
  • 举报
回复
我同意 Novolee(小李)
用一个SESSION保存你的IP地址
xxrl 2003-08-30
  • 打赏
  • 举报
回复
IIS里面的目录安全性-》编辑-》可访问的IP编辑。。。。。
李睿_Lee 2003-08-30
  • 打赏
  • 举报
回复
我也忙,没时间打代码.
给个思路吧:
1、取得访客的IP
2、判断IP是否在一定范围内,是的给一个SESSION赋值,在每个页面都要据此SESSION判断。
2、转入,或显示IP不在范围的提示
很简单的。
fallblood 2003-08-30
  • 打赏
  • 举报
回复
用判断语句来决定IP的地址,具体的做法还可以在服务器上限制IP的地址范围,当然需要修改一个页面,就是WIN自带的出错的那个页面,这个也许是最好的方法,具体的参看些资料吧!
最近太忙,没有时间打那么多字了
chjpeng 2003-08-30
  • 打赏
  • 举报
回复
參考一下動網的代碼,有在網頁中限制訪問ip

28,390

社区成员

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

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