1, simplify the code. (in fact, the definition of a few variables is removed)
2, for the information retrieved from InterNIC is too simple, according to InterNIC feedback information in the WHOIS server for further inquiries. For example, Yahoo has more detailed information on the whois.networksolutions.com.
Class Whois {
var $use _cache = 1;
var $FROM _cache=0;
var $cache _dir = "./"; Set yourself according to your system
var $port = 43;
var $MAXLEN = 100;
If you want to automatically retry after a failed connection,
Set the number of retries $MAX _retries
var $MAX _retries = 0;
var $SLEEP _val = 1;
var $RETRY = 0;
var $FOUND = 0; The query has no results and the secondary value is 0
var $ERROR = 0; Number of errors during query
var $DATA _min = 8; We should at least get 8 bytes of data
var $DATA _count = 0;
var $WHOIS _server;
var $NEW _whois;
var $FURTHER _info = 0;
Open the socket connection to the WHOIS server
The default is 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;
}
Get simple query results and put the array in the behavior unit
International Domain Name Query
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 ("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
}
Domestic Domain name Query
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 ("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;
Select Whois SERVER based on a domestic domain name or an international domain name
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 "
";
}
?>
http://www.bkjia.com/PHPjc/316451.html www.bkjia.com true http://www.bkjia.com/PHPjc/316451.html techarticle 1, simplify the code. (In fact, it is to remove some of the definitions of unnecessary variables) 2, the information retrieved from InterNIC is too simple, according to the InterNIC feedback information in the Whois SER ...