这是我的代码:
<?php
$targetsfile = $argv[1];
if(!isset($argv[1])) { echo "[-] Try again... with targets file.\n"; die(); }
error_reporting(-1);
ini_set('max_execution_time', 0);
$nodes = array();
$nodes = file("$targetsfile", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$node_count = count($nodes);
$curl_arr = array();
$master = curl_multi_init();
for($i = 0; $i < $node_count; $i++)
{
$agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; pt-pt) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27";
$url = $nodes[$i];
$curl_arr[$i] = curl_init($url);
curl_setopt($curl_arr[$i], CURLOPT_URL, $url);
curl_setopt($curl_arr[$i], CURLOPT_USERAGENT, $agent);
curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_arr[$i], CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_arr[$i], CURLOPT_MAXREDIRS, 2);
curl_setopt($curl_arr[$i], CURLOPT_VERBOSE, false);
curl_setopt($curl_arr[$i], CURLOPT_TIMEOUT, 20);
curl_multi_add_handle($master, $curl_arr[$i]);
}
do
{
curl_multi_exec($master, $running);
usleep(5000);
} while($running > 0);
for($i = 0; $i < $node_count; $i++)
{
$httpcode = curl_getinfo($curl_arr[$i], CURLINFO_HTTP_CODE);
if($httpcode>=200 && $httpcode<=300) {
$crawledlink = curl_getinfo($curl_arr[$i], CURLINFO_EFFECTIVE_URL);
echo "Parsing->" . $crawledlink;
}
}
?>
我应该怎样做才能让我的脚本开始解析网站,同时验证http代码,因为我正在考虑当我编写代码时,它会解析网站,同时验证http代码,但它不会...首先验证我的所有目标http代码,然后开始解析...我希望脚本立即开始解析网站,他发现1我的http代码200-299就像我指定的那样。
有什么建议吗?