WHOIS類的修改版

來源:互聯網
上載者:User
關鍵字 WHOIS類的修改版
1、簡化了代碼。(其實就是去掉了一些用不著的變數的定義)
2、針對從INTERNIC檢索到的資訊過於簡單,根據INTERNIC反饋的資訊中的WHOIS SERVER進行進一步查詢。比如,YAHOO在whois.networksolutions.com上有更詳細的資訊。

class whois { 

var $use_cache = 1; 
var $FROM_CACHE=0; 
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 $FURTHER_INFO = 0;


// 開啟和WHOIS SERVER的SOCKET串連
// 預設的是 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; 
} 

// 擷取簡單的查詢結果,並以行為單位,放入數組
// 國際網域名稱查詢
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;
} 


// 國內網域名稱查詢
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;
// 根據國內網域名稱或國際網域名稱選擇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 " 
";
}

?> 

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.