我是如何做到精准屏蔽一个省份用户的访问? by jiangchen

View this thread on steempeak.com
· @jiangchen ·
$0.82
我是如何做到精准屏蔽一个省份用户的访问?
![封面图](https://www.mhcf.net/content/uploadfile/202005/60ab1589506456.jpg)

自2019年10月18日起,梦幻辰风就开始针对这一个地方屏蔽了那一个地区的访问。

最初我是通过又拍云CDN来实现的,但是随着网站的备案号被注销后,又拍云CDN就暂停了我的接入。

随后呢,我采用了淘宝IP的API,但是发现有限制:每个用户的访问频率需小于1qps。作为一个文科生,我也不知道1qps是什么意思。随后,看着IPIP,发现那一家在线API也有限制——直接对梦幻辰风的IP返回429。

最后,在 @慕若曦 同学的帮助下,根据ipip的离线数据库搭建了自己用语验证的IP地址库。

在这里,我分享给大家的是 @羽忆江南 同学提供的API,如果您有需要,可以自己搭建。在微信搜索“梦幻辰风”,关注后回复“IP”即可下载程序(PHP脚本)。

至于如何使用?把以下代码放在网站的index.php头部即可。

作为一个菜鸡,只能用最详细的注释来保证自己不会忘记写的什么。如果这个能帮到你,十分荣幸。

    <?php
    /*
    * Title :定点屏蔽一个位置的访问
    * Author:姜辰
    * Time  :2020/03/17
    * About :这是基于 @羽忆江南 的API搭建的。这个IP数据库来自ipip.net的离线数据,有需要自己搭建的可以关注梦幻辰风公众回复“IP”获取下载。(感谢 @慕若曦 帮忙写的代码。)
    */
    header("Content-type:text/html; charset=utf-8");//确认好编码。
    error_reporting(0);//屏蔽报错
    if(empty($_COOKIE["UserCity"])){
        //没有cookies,第一次来吧?
        $api="https://yyer.net/ipip/user.php?ip=".$_SERVER['REMOTE_ADDR'];//接口
        $data=file_get_contents($api);//直接读取接口
        wall($data);//对接口进行处理
    }
    else{
        //有cookies,不是新人
        wall($_COOKIE["UserCity"]);
    }
    function wall($data){
        //一个很辣鸡的函数
        if($data=="台湾"){
            //我们选择要屏蔽的省份
            //拒绝访问的跳转地址
            header("Location: /NoAccess.html");
        }
        //如果不是我们要屏蔽访问的省份
        //那就为它写入Cookies
        setcookie("UserCity",$data,time()+2592000);//保存用户cookies,减少对API的访问
    }

这个在什么时候会用到呢?

比如,备案的时候你只想让你们管局无法访问?

比如,因为约谈的原因你需要拒绝一个地方的审查?

比如,你看姜辰不顺眼想屏蔽慕若曦所在的那个省份的访问?

假如,你想让某个地方少部分人可以访问呢?

给他们做一个APP客户端吧!然后在wall函数里,添加一个访问的参数,有那么参数直接写入可以访问的cookies。

最后,如果觉得有用,不如关注下“梦幻辰风”?
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 73 others
properties (23)
post_id86,008,198
authorjiangchen
permlink5vhzcg
categoryhive-180932
json_metadata{"tags":["cn","cn-reader","cn-curation","whalepower","cn-stem","steemstem","cn-programming","palnet","zzan","dblog","diamondtoken","marlians","neoxian","lassecash","upfundme","actnearn"],"image":["https:\/\/www.mhcf.net\/content\/uploadfile\/202005\/60ab1589506456.jpg"],"app":"steemcoinpan\/0.1","format":"markdown"}
created2020-05-15 01:38:42
last_update2020-05-15 01:38:42
depth0
children2
net_rshares2,367,619,640,010
last_payout2020-05-22 01:38:42
cashout_time1969-12-31 23:59:59
total_payout_value0.416 SBD
curator_payout_value0.408 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,566
author_reputation30,823,992,397,451
root_title我是如何做到精准屏蔽一个省份用户的访问?
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (137)
@cheetah ·
Hi! Did you know that steemit.com is now censoring users and posts based on their opinions?
 All the posts of these users are gone!
https://github.com/steemit/condenser/commit/3394af78127bdd8d037c2d49983b7b9491397296 

 Here's a list of some banned users:
```'roelandp', 'blocktrades', 'anyx', 'ausbitbank', 'gtg', 'themarkymark', 'lukestokes.mhth', 'netuoso', 'innerhive'```
See anyone you recognize? There could be more, they also have a remote IP ban list.

Will you be censored next?
properties (22)
post_id86,008,199
authorcheetah
permlinkcheetah-re-jiangchen5vhzcg
categoryhive-180932
json_metadata{}
created2020-05-15 01:38:51
last_update2020-05-15 01:38:51
depth1
children0
net_rshares0
last_payout2020-05-22 01:38:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length487
author_reputation750,854,098,279,735
root_title我是如何做到精准屏蔽一个省份用户的访问?
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@cnbuddy ·
你今天过的开心吗?请支持中文区的见证人, @abit @bobdos @ety001 @justyy @oflyhigh @partiko (首字母顺序),全投,一个都不要漏。假如我的留言打扰到你,请回复“取消”。
properties (22)
post_id101,138,112
authorcnbuddy
permlinkre-jiangchen-5vhzcg-20220919t102219997z
categoryhive-180932
json_metadata{}
created2022-09-19 10:22:21
last_update2022-09-19 10:22:21
depth1
children0
net_rshares0
last_payout2022-09-26 10:22:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length107
author_reputation-1,405,328,253,928
root_title我是如何做到精准屏蔽一个省份用户的访问?
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000