A class _php basis for domain name whois in PHP query

Source: Internet
Author: User
Copy Code code as follows:

?
Class Searchdomain
{
var $domain = "";
function SetDomain ($udomain)
{
$this->domain = $udomain;
}
//
Get whois and parse the domain name status
OK is not registered
Non-null Value Expiration Time
Null value Unknown
//
function GetInfo ()
{
/*
$dinfo = Trim ($this->getwhois ());
if ($dinfo = = "") return "";
if (eregi ("No Match", $dinfo)) return "OK";
return $rs;
*/
$WL = "";
$w _server = $this->getserver ();
if ($w _server== "") return "";
$fp = Fsockopen ($w _server, $errno, $errstr, 30);
if (! $fp)
{
Echo $errstr;
Return "";
}
$out = $this->domain. " \ r \ n ";
$out. = "connection:close\r\n\r\n";
Fputs ($fp, $out);
while (!feof ($FP))
{
$WL = fgets ($fp, 255);
if (eregi ("No Match", $WL))
{
Fclose ($FP);
return "OK";
}
if (eregi ("Expiration Date", $WL))
{
$lines = Split (":", $WL);
$t = Trim ($lines [1]);
$ts = Split ("", $t);
$t = $ts [0];
if (Ereg ("[^0-9-]", $t))
{
$ts = Split ("-", $t);
$t = $ts [2]. " -". $this->monthtonum ($ts [1])." -". $ts [0];
}
Fclose ($FP);
return $t;
}
}
Fclose ($FP);
Return "";
}
//
Get the entire WHOIS information for the domain name
//
function Getwhois ()
{
$WH = "";
$w _server = $this->getserver ();
if ($w _server== "") return "";
$fp = Fsockopen ($w _server, $errno, $errstr, 30);
if (! $fp)
{
Echo $errstr;
Return "";
}
$out = $this->domain. " \ r \ n ";
$out. = "connection:close\r\n\r\n";
Fputs ($fp, $out);
while (!feof ($FP))
{
$wh. = NL2BR (fgets ($fp, 255));
}
Fclose ($FP);
return $WH;
}
//
Output status information for the current domain name
//
function Printsta ()
{
$rs = $this->getinfo ();
if ($rs = = "OK") echo $this->domain. "Not registered! <br/>\r\n ";
else if ($rs = = "") echo "Cannot query". $this->domain. "State!" <br/>\r\n ";
else echo $this->domain. "Registered, due time: $rs <br/>\r\n";
}
//
Get WHOIS query server
//
function Getserver ()
{
$udomain =substr ($this->domain,-3);
Switch ($udomain)
{
Case "com":
$w _server= "Whois.internic.net";
Break
Case "NET":
$w _server= "Whois.internic.net";
Break
Case "org":
$w _server= "whois.pir.org";
Break
Case "NFO":
$w _server= "Whois.afilias.info";
Break
Case "Biz":
$w _server= "Whois.biz";
Break
Case ". CC":
$w _server= "whois.nic.cc";
Break
Case "Edu":
$w _server= "Whois.educause.net";
Break
Case "gov":
$w _server= "whois.nic.gov";
Break
Case ". CN":
$w _server= "whois.cnnic.net.cn";
Break
Default
$w _server= "";
}
return $w _server;
}
//
English month to Digital
//
function Monthtonum ($m)
{
$m = Strtolower ($m);
For ($i =1 $i <=12; $i + +)
{
$tt = Mktime (0,0,0, $i +1,0,2005);
if ($m ==strtolower (strftime ("%b", $tt))
{
if ($i >9) return $i-1;
else return "0". $i-1;
}
}
}
}

$SD = new Searchdomain ();
$SD->setdomain ("job-sky.com");

Query domain name is registered, equivalent to $SD->printsta ();
$rs = $sd->getinfo ();
if ($rs = = "OK") echo $sd->domain. "Not registered! <br/>\r\n ";
else if ($rs = = "") echo "Cannot query". $SD->domain. "State!" <br/>\r\n ";
else echo $sd->domain. "Registered, due time: $rs <br/>\r\n";

Obtain detailed whois information for a domain name
echo $SD->getwhois ();
?>

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.