Boring incredibly and find a PHP version of the crawl Google hosts files, try the next can also use, ping the next IP, the delay is not very high, the Web page opened test under the speed is also very fast, we are interested to try.
Automatically update the Hosts file, do not overwrite existing records, easy to use, do not copy-> every time you open the Hosts file-> paste.
PHP File:
<?php/** * Free to flip on the wall Google * @author amuse oneself <wapznw@gmail.com> * DATE:2015/2/6 * time:11:42 * * 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 ', ' OpenBSD ', ' WIN32 ', ' Windows ', ' Unix ')) {define (' Hosts_
File_path ', '/etc/hosts '); }else{die (' Unsupported 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;
}