Shield domestic IP addresses. authentication is required for access.

Source: Internet
Author: User
To shield domestic IP addresses, access requires authentication. a foreign trade website wants to shield domestic IP addresses, but we need to manage and allow specific domestic users to access the website. Therefore, authentication is required, how can this function be implemented? Please pay more attention to the first post! Thank you! ------ Solution ------------------ you can create a page. During user access, 1. obtain the user's IP2. then go to the open IP interface to query the user's geographical location (for example, Sina, Netease, and ip shield domestic IP addresses). authentication is required for access.
A foreign trade website wants to shield domestic IP addresses, but we need to manage and allow specific domestic users to access the website. so we need to perform authentication. how can this function be implemented? Please pay more attention to the first post! Thank you!

------ Solution --------------------
You can create a page,
1. get the user's IP address
2. then, go to the open IP interface to query users' geographic locations (for example, Sina, Netease, and ip138 all have open ip address query interfaces)
3. determine whether to block or verify the location of the user.
------ 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 ("//", $ str) |! Preg_match ("/", $ str ))? $ Location ['sp '] = $ tmp [7]: $ location ['sp'] = $ tmp [6]; $ location ['Time'] = microtime (TRUE) -$ php_runtime; if (! Empty ($ location) return $ location; else return false ;}
------ Solution --------------------
You can use the IP address to determine which subnet the IP belongs, for example, 110.80.0.0/13.
Place all the subnets that can be divided in China into an array and check whether they are in this array.

You do not need to query the address through other interfaces, and then judge the address or carrier name. This is troublesome.
PS: This array is not large, with less than 800 entries.

Please refer to this page for the conversion method: http://url.cn/0TCFrY with all China can be divided into subnets 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 and extraction, and then the IP address can be filtered.

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.