WHOIS類的更改版。
發(fā)表時(shí)間:2023-08-08 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]1、簡(jiǎn)化了代碼。(其實(shí)就是去掉了一些用不著的變量的定義)2、針對(duì)從INTERNIC檢索到的信息過于簡(jiǎn)單,根據(jù)INTERNIC反饋的信息中的WHOIS SERVER進(jìn)行進(jìn)一步查詢。比如,YAHOO在w...
1、簡(jiǎn)化了代碼。(其實(shí)就是去掉了一些用不著的變量的定義)
2、針對(duì)從INTERNIC檢索到的信息過于簡(jiǎn)單,根據(jù)INTERNIC反饋的信息中的WHOIS SERVER進(jìn)行進(jìn)一步查詢。比如,YAHOO在whois.networksolutions.com上有更詳細(xì)的信息。
<?
class whois {
var $use_cache = 1;
var $FROM_CACHE=0;
var $cache_dir = "./";// 根據(jù)你的系統(tǒng)自己設(shè)置
var $port = 43;
var $MAXLEN = 100;
// 如果你想在連接失敗后自動(dòng)重試,
// 設(shè)置重試次數(shù) $MAX_RETRIES
var $MAX_RETRIES = 0;
var $SLEEP_VAL = 1;
var $RETRY = 0;
var $FOUND = 0;// 查詢沒有結(jié)果,次值為0
var $ERROR = 0;// 查詢過程中的出錯(cuò)次數(shù)
var $DATA_MIN = 8; // 我們至少應(yīng)該獲得8個(gè)字節(jié)的數(shù)據(jù)
var $DATA_COUNT = 0;
var $WHOIS_SERVER;
var $NEW_WHOIS;
var $FURTHER_INFO = 0;
// 打開和WHOIS SERVER的SOCKET連接
// 默認(rèn)的是 whois.internic.net
function connect ($server) {
$this->RETRY=0;
while($this->RETRY <= $this->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++;
$this->RETRY++;
sleep($this->SLEEP_VAL);
endif;
endwhile;
}
// 獲取簡(jiǎn)單的查詢結(jié)果,并以行為單位,放入數(shù)組
// 國(guó)際域名查詢
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($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++;
$this->FOUND=0;
elseif(eregi( "Please wait a while and try again",$array[$i])):
$this->ERROR++;
$this->FOUND=0;
break;
endif;
if(eregi("Whois 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);
if($this->DATA_COUNT>$this->DATA_MIN):
return($array);
else:
$this->ERROR++;
endif;
else:
$this->ERROR++;
endif;
}
// 國(guó)內(nèi)域名查詢
function cnrawlookup ($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($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++;
$this->FOUND=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>$this->DATA_MIN):
return($array);
else:
$this->ERROR++;
endif;
else:
$this->ERROR++;
endif;
}
};
$myWHOIS=new whois();
$thisname=$servername.$domainname;
// 根據(jù)國(guó)內(nèi)域名或國(guó)際域名選擇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 "<h2 align=center>".$thisname."</h2>";
echo "<table>";
$x=0;
while ($x<count($array))
{
echo "<tr><td>$x</td>";
echo "<td>$array[$x]</td>";
$x++;
}
echo "";
if (!ereg(".cn$",$thisname))
{
echo "<h2 align=center>Furth infomation</h2>";
$array_further=$myWHOIS->rawlookup($thisname,$myWHOIS->NEW_WHOIS);
echo "<table>";
$x=0;
while ($x<count($array_further))
{
echo "<tr><td>$x</td>";
echo "<td>$array_further[$x]</td>";
$x++;
}
echo "";
}
?>