Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  Asp  >  正文 ASP脚本限制某IP段访问的代码

ASP脚本限制某IP段访问的代码

发布时间:2014-07-20   编辑:www.jquerycn.cn
分享下asp脚本限制某Ip段访问网页的代码,有需要的朋友参考下。

对某段IP做限制访问指定网页。

方法一:
 

复制代码 代码示例:
<html>  
<head>  
<title>限制IP段访问</title>  
</head><body>  
<% 
function IP2Num(sip) 
    dim str1,str2,str3,str4 
    dim num 
    IP2Num=0 
    if isnumeric(left(sip,2)) then 
        str1=left(sip,instr(sip,".")-1) 
        sip=mid(sip,instr(sip,".")+1) 
        str2=left(sip,instr(sip,".")-1) 
        sip=mid(sip,instr(sip,".")+1) 
        str3=left(sip,instr(sip,".")-1) 
        str4=mid(sip,instr(sip,".")+1) 
        num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4) 
        IP2Num = num 
    end if 
end function 
 
function Num2IP(nip) 
    iip1 = int(nip/256/256/256) 
    iip2 = int((nip-iip1*256*256*256)/256/256) 
    iip3 = int((nip-iip1*256*256*256-iip2*256*256)/256) 
    iip4 = int((nip-iip1*256*256*256-iip2*256*256-iip3*256) mod 256) 
    iip0 = iip1 &"."& iip2 & "." &iip3 &"."& iip4 
    Num2IP = iip0 
end function 
 
userIPnum = IP2Num(Request.ServerVariables("REMOTE_ADDR")) 
 
if userIPnum > IP2Num("192.168.150.0") and userIPnum < IP2Num("192.168.150.138") then 
    response.write ("<center>您的IP被禁止</center>") 
    response.end 
    else response.write ("<center>您的IP被未被限制!</center>") 
end if 
%> 
</body></html> 

方法二:
 

复制代码 代码示例:
<html>  
<head>  
<title>限制IP段访问—www.jquerycn.cn</title>  
</head><body>  
<% 
'限制192.168.150.130(3232274049)到192.168.150.140(3232274059) 
 
ip=request.servervariables("remote_addr") 
sip=split(ip,".") 
num=cint(sip(0))*256*256*256+cint(sip(1))*256*256+cint(sip(2))*256+cint(sip(3))-1 
response.write(ip) 
response.write("<br>") 
if (num >= 3232274049 and num <= 3232274059) then 
    response.write("您的ip被限制!") 
    response.End() 
  else 
    response.write("您的ip未被禁止") 
end if 
%>  
</body></html>

您可能感兴趣的文章:
php限制单个IP与ip段访问的代码
PHP限制IP段访问实现代码
ASP脚本限制某IP段访问的代码
如何用php实现IP访问限制
php 禁止单个IP地址或IP段访问的实现代码
php禁止ip访问的函数
PHP根据IP地址限制用户访问
限制ip地址段访问用php如何实现
php IP与IP段访问限制的实现代码
限制ip地址段访问的php代码

关键词: IP段限制  IP访问限制   
[关闭]