PHP implementation crawl Google IP and automatically modify the Hosts file _php instance

Source: Internet
Author: User

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;
 }

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.