This article mainly introduces PHP to capture GoogleIP and automatically modify the hosts file. This article can be used to achieve google without turning over the wall, if you need a friend, you can refer to the boring section and find another php version to capture the google hosts file. If you try again, you can use it. After you ping the ip address, the latency is 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 ;}