PHP captures GoogleIP and automatically modifies the hosts file

Source: Internet
Author: User
This article mainly introduces how to capture GoogleIP addresses in PHP and automatically modify the hosts file. This article can be used to achieve google without turning over the wall.

This article mainly introduces how to capture Google IP addresses in PHP and automatically modify the hosts file. This article provides a method to achieve google without turning over the wall.

Bored, I found another php version to capture the google hosts file. I tried it and tried it again. I pinged the ip address, and the latency was not very high, the web page is opened and tested quickly. If you are interested, try it.

The hosts file is automatically updated, which does not overwrite existing records and is easy to use. You do not need to copy the file every time-> open the hosts file-> paste it.

PHP file:

<? Php/*** open the wall free google * @ author self-entertainment * Date: * Time: */define ('start _ tag', '# google-hosts-2015'); define ('end _ tag', '# google-hosts-2015-end '); if (! Empty ($ argv [1]) {$ params = array (); parse_str ($ argv [1], $ params ); if (isset ($ params ['url']) {define ('Google _ HOST_URL ', $ params ['url']);} if (isset ($ params ['del ']) {define ('delete _ GOOGLE_HOST', true) ;}} defined ('Google _ HOST_URL ') | define ('Google _ HOST_URL ',' http://www.360kb.com/kb/2_150.html '); If (PHP_ OS = 'winnt') {define ('hosts _ FILE_PATH ', 'c: WindowsSystem32driversetchosts');} else if (in_array (PHP_ OS, array ('linux ', 'darwin', 'freebsd', 'opensdk', 'win32 ', 'windows', 'unix '))) {define ('hosts _ FILE_PATH ','/etc/hosts');} else {die ('unororted system! '. PHP_EOL);} if (! Is_writable (HOSTS_FILE_PATH) {die ('without permission, please use the root user to perform! '. PHP_EOL);} $ hosts = file_get_contents (HOSTS_FILE_PATH); $ startPos = strpos ($ hosts, START_TAG); if (! Defined ('delete _ GOOGLE_HOST ') {$ gs = get_google_hosts (); echo GOOGLE_HOST_URL.PHP_EOL; echo $ gs. PHP_EOL;} else {$ gs = ''; echo 'reset hosts '. PHP_EOL;} if ($ startPos) {$ _ tmp = substr ($ hosts, $ startPos, strpos ($ hosts, END_TAG)-$ startPos + strlen (END_TAG )); $ hosts = str_replace ($ _ tmp, $ gs, $ hosts);} else {$ hosts. = PHP_EOL. $ gs;} $ old_file_size = filesize (HOSTS_FILE_PATH); if (file_put_contents (HOSTS_FILE_PATH, $ hosts) {die ('success. '. PHP_EOL);} else {die ('fail '. PHP_EOL);} function get_google_hosts () {$ html = file_get_contents (GOOGLE_HOST_URL); $ html = strip_tags ($ html); $ startPos = strpos ($ html, START_TAG ); $ html = substr ($ html, $ startPos, strpos ($ html, END_TAG)-$ startPos); $ html = str_replace ('','', $ html ); return $ html. PHP_EOL.END_TAG ;}

,
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.