PHP实现调用必应旁站C段查询-Meiam's Home

 

<?php
 
print_r( 
" 
+------------------------------------+ 
旁站 and C段查询 
 
Example: 
php.exe $argv[0] -p 192.168.1.1
php.exe $argv[0] -c 192.168.1.1 1 254
 
  
结果保存在url.txt里面!
+------------------------------------+ 
rnrnrn" 
); 

$file="url.txt";
if(file_exists($file)) {
unlink ($file);
}
if(empty($argv[2])) exit("i请输出IP地址"); 
$ip=gethostbyname($argv[2]);

switch($argv[1]){
 case "-p":
     bing($ip);
     break;
 case "-c":
     c($ip);
        break; 
  default:
    echo "错误:请根据参数输入";
}

function c($sb){
 
$str=(explode(".",$sb)); 
global $argv;  
for($vip=$argv[3];$vip&lt;=$argv[4];$vip++){ 
	$newip=$str[0].".".$str[1].".".$str[2].".".$vip; 
	echo "正在查询$newip-------------rn"; 
	bing($newip); 
	}
}

if(file_exists($file)) {
$file=file("url.txt");
echo "rnurl.txt查询到".count($file)."个";
} 


 
function bing($ip){ 
$first=1;
 
	do {
	ini_set('user_agent', 'Baiduspider');
	$a=file_get_contents("http://www.bing.com/search?count=50&amp;q=ip%3a$ip&amp;qs=n&amp;pq=ip%3a$ip&amp;sc=0-0&amp;sp=-1&amp;sk=&amp;first=".$first."&amp;FORM=PQRE");
	$a=mb_convert_encoding($a, "GBK", "UTF-8");
	$first+=50;
	preg_match_all("/&lt;h2&gt;&lt;a href="(.*)&lt;/a&gt;&lt;/h2&gt;/isU",$a,$arr);
	preg_match_all("/&lt;h2&gt;&lt;a href="(.*)" target="_blank/isU",$a,$urlarr);
	$arr[1] = preg_replace('/" target="_blank"(.*).1"&gt;/isU','-----------',$arr[1]);
	unset($arr[0]);
	foreach ($arr as $key=&gt;$r){
	foreach ($r as $k=&gt;$rc){
		$arrs = parse_url($rc); 
		if ($arrs['host'] &lt;&gt; "ip.chinaz.com"){   
			echo $arrs['host']."rn";
			file_put_contents("url.txt", $arrs['host']."rn",FILE_APPEND);
			}    
		}
    }      
} while (strpos($a,"&gt;下一页&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;"));
 
}
 
 ?>