个实现Whois的类 
出自:代码实验室 chris 2002年09月03日 22:08 
这个Whois类中只有一个方法,通过这个方法可以对几乎所有的domain name进行查询,并将查询结果返回。但对于新的domain name例如:.tv,.info,.biz等还不支持。代码如下:<?
Class Whois
{
var $whois_server;
var $timeout = 30;function lookup($domain)
{
$result = "";
$parts = array();
$host = "";// .tv don't allow access to their whois
if (strstr($domain,".tv"))
{
$result = "'.tv' domain names require you to have an account to do whois searches.";
// New domains fix (half work, half don't)
} elseif (strstr($domain,".name") || strstr($domain,".pro") >0){
$result = ".name,.pro require you to have an account to do whois searches.";
} else{
if (empty($this->whois_server))
{
$parts = explode(".",$domain);
$testhost = $parts[sizeof($parts)-1];
$whoisserver = $testhost . ".whois-servers.net";
$this->host = gethostbyname($whoisserver);
$this->host = gethostbyaddr($this->host);if ($this->host == $testhost)
{
$this->host = "whois.internic.net";
}
flush();
}
$whoisSocket = fsockopen($this->host,43, $errno, $errstr, $this->timeout);if ($whoisSocket)
{
fputs($whoisSocket, $domain."1512");
while (!feof($whoisSocket))
{
$result .= fgets($whoisSocket,128) . "<br>";
}
fclose($whoisSocket);
}
}
return $result;
}
}
?>上面的代码中定义了一个方法:lookup($domain),下面的这段代码就是测试这个类的功能的。<? 
include("clsWhois.php"); 
$whois = new Whois(); 
echo $whois->lookup("code-labs.com"); 
?>