屏蔽某地區(城市)訪問網站


上級領導檢查網站?百度競價臨時檢查?你總會遇到各式各樣的臨時問題。以下代碼可以實現指定地區(城市)禁止訪問。原理是根據IP地址歸屬地區來進行篩選,進行跳轉。

<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" charset="GB2312" ></script>
<script type=text/javascript>
 if(remote_ip_info.city =='成都'){
  window.location.href="跳轉鏈接";
 }
</script>

 由於http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪接口目前用不了,所以上面代碼沒法執行,下面講用126網易接口的

代碼1:

 

<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>無標題文檔</title>
<script type="text/javascript" src="http://ip.ws.126.net/ipquery"></script>
<script>
var province=localAddress.province;//獲取所在省,比如廣東省
var city=localAddress.city;//獲取所在市,比如廣州市
//判斷省
if(province.indexOf('廣東')  != -1){
    alert(province);    
    }else{
        }
//判斷市
if(city.indexOf('廣州')  != -1){
    alert(city);    
    }else{
        }
</script>
</head>
<body>
<p>12345678</p>
</body>
</html>

 

代碼2:

<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>無標題文檔</title>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$.getScript('http://ip.ws.126.net/ipquery', function(){  
     console.log(localAddress.city)
    if(localAddress.city.indexOf('北京') != -1||localAddress.city.indexOf('杭州') != -1||localAddress.city.indexOf('上海') != -1||localAddress.city.indexOf('廣州') != -1||localAddress.city.indexOf('深圳') != -1||localAddress.city.indexOf('東莞') != -1||localAddress.city.indexOf('房山') != -1){        
       window.location.href = 'http://www.baidu.com';      
    }else{        
     return;      
    }
    console.log(localAddress.province)    
    if(localAddress.province.indexOf('福建') != -1){        
       window.location.href = 'http://www.baidu.com';      
    }else{        
     return;      
    }    
});
</script>
</head>

<body>
<p>123456789</p>


</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM