Shielding domestic IP, access needs to be authenticated to solve the idea

Source: Internet
Author: User
Block domestic IP, Access requires authentication
There is a foreign trade site want to block the domestic IP, but we need to manage and allow specific domestic users to access so to be authenticated, how can such a function be implemented? First post, please pay more attention! Thank you!

------Solution--------------------
Can make a page, when the user visits,
1. Get the IP of the user
2. Then go to the open IP interface to query the user's geographical location (such as Sina, NetEase, ip138, there are open IP query interface)
3. With the user's geographical location, then decide whether to block it, or verify the
------Solution--------------------
PHP Code
function Sina ($ip) {$php _runtime = Microtime (TRUE);    $str = file_get_contents ("http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=". $ip);    $tmp = Explode ("", $str); (Isset ($tmp [4]) &&!empty ($tmp [4])?    $location [' country '] = $tmp [4]: $location [' country '] = null; (Isset ($tmp [5]) &&!empty ($tmp [5])?    $location [' city '] = $tmp [5]: $location [' city '] = null; (Empty ($tmp [6]) | |!preg_match ("/Power/", $str) | |!preg_match ("/Pass/", $STR))?    $location [' sp '] = $tmp [7]: $location [' sp '] = $tmp [6];    $location [' time '] = Microtime (TRUE)-$php _runtime;    if (!empty ($location)) return $location; else return false;}
------Solution--------------------
The IP address that the user visited can be used to figure out which subnet the IP belongs to, such as 110.80.0.0/13
The entire China can be divided into an array of subnets, to determine whether in this array is OK.

Do not need to go to other interfaces to query the address, and then according to the address or operator's name to judge, but trouble.
PS: This array is small, less than 800.

The method of conversion please see this page: Http://url.cn/0TCFrY with all the Chinese can be divided into sub-network Excel download


------Solution--------------------
Ftp://ftp.apnic.net/public/apnic/stats/apnic/delegated-apnic-latest

apnic| cn|ipv4|180.212.0.0|131072|20091001|allocated

This is the domestic. Analysis extraction. And then filter the IP to do it.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.