1.簡化了程式碼。 (其實就是去掉了一些用不著的變數的定義)
以上就介紹了www.haoyisheng.com WHOIS類的修改版,包括了www.haoyisheng.com方面的內容,希望對PHP教程有興趣的朋友有所幫助。
2、針對從INTERNIC檢索到的信息過於簡單,根據INTERNIC反饋的信息中的WHOIS SERVER進行進一步查詢。例如,YAHOO在whois.networksolutions.com上有更詳細的資訊。
class whois {
var $use_cache = 1;
var $FROM_CACHE=0;
var $cache_dir = "./"; // 依照你的系統自行設定
var $cache_dir = "./"; // 依照你的系統自行設定
var $port = 43;
var $MAXLEN = 100;
// 若您想在連線失敗後自動重試,
// 設定重試次數$MAX_RETRIES
var $MAX_RETRIES = 0; >var $SLEEP_VAL = 1;
var $RETRY = 0;
var $FOUND = 0; // 查詢沒有結果,次值為0
var $ERROR = 0; // 查詢過程中的出錯次數
var $DATA_MIN = 8; // 我們至少應該取得8個位元組的資料
var $DATA_COUNT = 0;
var $WHOIS_SERVER;
var $NEW_WHOIS var $WHOIS_SERVER;
var $NEW_WHOIS;
var $WHOIS_SERVER;
var $NEW_WHOIS $FURTHER_INFO = 0;
// 開啟和WHOIS SERVER的SOCKET連線
// 預設的是whois.internic.net
function connect ($server) {
$this->RETRY=0->RETRY=0 ;
while($this->RETRY MAX_RETRIES):
$ptr = fsockopen($server, $this->port);
if($ptr>0):
$this->ERROR=0; // just in case we're on a retry
return($ptr);
else:
$this->ERROR++
sleep($this->SLEEP_VAL);
endif;
endwhile;
}
// 取得簡單的結果,並以簡單的資訊方式放入數組>// 國際網域查詢
function rawlookup ($query, $server) {
if(!$query):
return( "");
endif;
$ptr=$ this->connect($server);
if($ptr):
if(!ereg($query, "n$")):
$query .= "n";
endif;
fputs($ptr, "$query");
$i=0;
$this->FOUND=1;
while(!feof($ >$array[$i]=fgets($ptr,$this->MAXLEN);
$this->DATA_COUNT+=strlen(chop($array[$i]));
if(eregi( " No match for", $array[$i]) || eregi ("No entries found", $array[$i])):
$this->FOUND=0;
elseif(eregi( " WHOIS database is down",$array[$i])):
$this->ERROR++;
$this->FOUND=0;
elseif(eregi( "Please wait a while and
elseif(eregi("Please wait a while and wawait a ",$array[$i])):
$this->ERROR++;
$this->FOUND=0;
break;
endif;
break;
endif; Server:",$array[$i])):
$this->NEW_WHOIS=trim(substr(trim($array[$i]),(strlen(trim($array[$i]))- 13)*(-1)));
$this->FURTHER_INFO=1;
endif;
$i++;
endwhile;
fclose($ptr); ($this->DATA_COUNT>$this->DATA_MIN):
return($array);
else:
$this->ERROR++;
endif .; $this->ERROR++;
endif;
}
// 國內網域查詢
function cnrawlookup ($query, $server) {
if(!$query): ( "");
endif;
$ptr=$this->connect($server);
if($ptr):
if(!ereg($query, "n$" )):
$query .= "n";
endif;
fputs($ptr, "$query");
$i=0; while(!feof($ptr)):
$array[$i]=fgets($ptr,$this->MAXLEN);
$this->DATA_COUNT+=strlen(chop( $array[$i]));
if(eregi( "No match for", $array[$i]) || eregi ("No entries found", $array[$i])):
$this->FOUND=0;
elseif(eregi( "WHOIS database is down",$array[$i])):
$this->ERROR++;
$thisFOUND=$this->ERROR++;
$thisFOUND= 0;
elseif(eregi( "Please wait a while and try again",$array[$i])):
$this->ERROR++;
$this->FOUND=0; >break;
endif;
$i++;
endwhile;
fclose($ptr);
if($this-DATA_COUNT.DATA_COUNT. ($array);
else:
$this->ERROR++;
endif;
else: $myWHOIS=new whois();
$thisname=$servername.$domainname;
// 根據國內網域名稱或國際網域名稱選擇WHOIS SERVER
if (ereg(".cn$ ",$thisname))
{
$myWHOIS->WHOIS_SERVER="whois.cnnic.net.cn";
$array=$myWHOIS->cnrawlookup($thisname,$myWHOIS->WHOIS_SERVER) ;
}
else
{
$myWHOIS->WHOIS_SERVER="whois.internic.net";
//$myWHOIS->WHOIS_SERVER="whois.networksolutions.com";
$array= $myWHOIS->rawlookup($thisname,$myWHOIS->WHOIS_SERVER);
}
echo "
".$thisname."
";
echo "";
$ x=0;
while ($x {
echo " $x ";
echo " $array[$x] ";
$x++;
}
echo "
";
if (!ereg(".cn$",$thisname))
{
echo "
Furth infomation
";
$array_further=$myWHOIS- >rawlookup($thisname,$myWHOIS->NEW_WHOIS);
echo "";
$x=0;
while ($x {
echo " $x ";
echo " $array_further[$x] ";
$x++;
}
echo "
";
}
?>