改了改之前那个很糙的XXX

将就着用X度去爬吧

 1 <?php
 2 echo "***************************************\r\n";
 3 echo "*   SubDomain Spider                  *\r\n"; 
 4 echo "*   Author:Debug0                     *\r\n";
 5 echo "***************************************\r\n\r\n";
 6 if($argc<3)
 7 {
 8     echo "Usage:php $argv[0] Domain depth\r\n\r\n";
 9     echo "Example:php $argv[0] qq.com 101\r\n";
10     die();
11 }
12 $domain=$argv[1];
13 $page=0;
14 $curl=curl_init(); 
15 $output="";   
16 while($page<=$argv[2])  
17 { 
18     $query="/s?wd=site%3A($domain)&pn=".$page;
19     $page+=10;  //默认每页10条结果,所以翻页加10 
20     $url="http://www.baidu.com".$query; 
21     curl_setopt($curl, CURLOPT_URL, $url); 
22     curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); 
23     $output.=curl_exec($curl); 
24 }
25 $regexp="/g\">.*".$domain."\//i";
26 $result=array(); 
27 preg_match_all($regexp, $output, $result); 
28 $result2=$result[0];
29 foreach($result2 as $k=>$v)
30 {
31     $result2[$k]=trim($v,"g\">");
32     $pos=strpos($result2[$k],"/");
33     $result2[$k]=substr($result2[$k],0,$pos);
34 }
35 $result2=array_unique($result2);
36 foreach ($result2 as $v) {
37     echo $v."\r\n";
38 }
39 $num=count($result2);
40 echo "\r\nTotal SubDomains: ".$num;
41 ?>

 

posted @ 2015-08-05 17:41  不断学习中的小菜鸟  阅读(181)  评论(0编辑  收藏  举报