<?php
/**********************************************************************
Author:Mr.Chen
QQ number:505185182
mail:diankejava@gmail.com
Please keep this head,thank you
*********************************************************************/
function get_file($host,$path="/"){
$fp=fsockopen($host,80,$errno,$errstr,30);
$header = "GET ".$path." HTTP/1.1/r/n";
$header.= "Host : ".$host." /r/n";
$header.= "Connection: Keep-Alive/r/n/r/n";
fwrite($fp,$header);
$str="";
while(!feof($fp)){
$str.=fgets($fp,128);
}
return $str;
fclose($fp);
}
function write_log($str){
if(!is_dir("log")){
$writeable=mkdir("log",0777);
if(!$writeable){
exit("sorry! you dir is unwriteable!");
}
}
$fp=fopen("log/log.txt","a+");
fwrite($fp,$str,strlen($str));
fwrite($fp,"/r/n");
fclose($fp);
}
function analysis($str,$host="localhost"){
$html=array();
$pattern="/(href=)[/'|/"]([^/'/"]+)[/'|/"]/i";
preg_match_all($pattern,$str,$match);
if(is_array($match[2])){
foreach($match[2] as $key=>$value){
if(preg_match("/http:/",$value)){
$html[]=$value;
}else{
if(!preg_match("/^(//)*/",$value)){
$value="/".$value;
}
$html[]="http://".$host.$value;
}
}
}else{
if(preg_match("/http:/",$match[2])){
$html[]=$match[2];
}else{
if(!preg_match("/^(//)*/",$match[2])){
$value="/".$match[2];
}else{
$value=$match[2];
}
$html[]="http://".$host.$value;
}
}
return array_unique($html);
}
function get_host($str){
$host=array();
$pattern="/^(http:)?([^//]+)(.*)/";
if(preg_match($pattern,$str,$match)){
$host["host"]=$match[2];
$host["path"]=$match[3];
}else{
$host["host"]="";
$host["path"]="";
}
return $host;
}
?>