[ip跳转]不同地区IP显示不同内容,屏蔽部分地区的js代码

来源:ip跳转 浏览:1611次 时间:2021-03-13
做网站找雨过天晴工作室

[ip跳转]不同地区IP显示不同内容,屏蔽部分地区的js代码

利用百度的ip地址识别

https://baiducdncss.com/ip2region/iplookup.php

这个是识别的代码

var remote_ip_info = {"success":1,"country":"\u4e2d\u56fd","district":"\u534e\u4e2d","province":"\u6cb3\u5357\u7701","city":"\u90d1\u5dde\u5e02","isp":"\u7535\u4fe1"};


然后经过国家,省份,城市的判断,进行跳转。

以下是代码

<script src="https://baiducdncss.com/ip2region/iplookup.php" charset="utf-8"></script>
<script type="text/javascript">
var $B = false;
var $Guo = ["菲律宾","老挝","泰国","缅甸","柬埔寨","马来西亚","新加坡","印度尼西亚","尼泊尔","帕劳"]; //unicode
var $Sheng = ["北京市"]; //unicode
var $Shi = ["上海市"]; //unicode
var $Shi = ["北京市"]; //unicode
var $Sheng = ["上海市"];
var $Sheng = ["湖北省"];
if ($Guo.length > 0) {
for (var i = $Guo.length - 1; i >= 0; i--) {
if (remote_ip_info.country.indexOf($Guo[i]) != -1) {
$B = true;
break;
}
}
}
if ($Sheng.length > 0) {
for (var i = $Sheng.length - 1; i >= 0; i--) {
console.log($Sheng[i]);
if (remote_ip_info.province.indexOf($Sheng[i]) != -1) {
$B = true;
break;
}
}
}
if ($Shi.length > 0) {
for (var i = $Shi.length - 1; i >= 0; i--) {
if (remote_ip_info.city.indexOf($Shi[i]) != -1) {
$B = true;
break;
}
}
}
if ($B) {
window.location.href = '/404.html'; //定义404跳转
} else {
window.location.href = 'https://' + 'baidu.com'; //正常跳转
}
</script>