Modified version of the Whois class

Source: Internet
Author: User
Tags array chop ereg connect sleep strlen trim domain name
1, simplified the code. (It actually removes some of the variables that you don't need to define)
2, for the information retrieved from the InterNIC is too simple, according to InterNIC feedback in the information of WHOIS server for further inquiries. Yahoo, for example, has more detailed information on the whois.networksolutions.com.

Class Whois {

var $use _cache = 1;
var $FROM _cache=0;
var $cache _dir = "./"; Set it up according to your system.

var $port = 43;
var $MAXLEN = 100;

If you want to try again automatically after the connection fails,
Set the number of retries $MAX _retries
var $MAX _retries = 0;
var $SLEEP _val = 1;
var $RETRY = 0;

var $FOUND = 0; Query has no results, the secondary value is 0
var $ERROR = 0; Number of errors during query
var $DATA _min = 8; We should get at least 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 a simple query result and put the array in the behavior unit
International Domain name Inquiry
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 (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 Search
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;
Select Whois SERVER according to domestic domain name or 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 "
";
}

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.