Copy codeThe Code is as follows:
<?
Class SearchDomain
{
Var $ domain = "";
Function SetDomain ($ udomain)
{
$ This-> domain = $ udomain;
}
//
// Obtain whois and analyze the domain name status
// OK is not registered
// Non-null 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, 43, $ errno, $ errstr, 30 );
If (! $ Fp)
{
Echo $ errstr;
Return "";
}
$ Out = $ this-> domain. "\ r \ n ";
$ Out. = "Connection: Close \ 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-]", $ t ))
{
$ Ts = split ("-", $ t );
$ T = $ ts [2]. "-". $ this-> MonthToNum ($ ts [1]). "-". $ ts [0];
}
Fclose ($ fp );
Return $ t;
}
}
Fclose ($ fp );
Return "";
}
//
// Obtain the whole whois information of the domain name
//
Function GetWhois ()
{
$ Wh = "";
$ W_server = $ this-> GetServer ();
If ($ w_server = "") return "";
$ Fp = fsockopen ($ w_server, 43, $ errno, $ errstr, 30 );
If (! $ Fp)
{
Echo $ errstr;
Return "";
}
$ Out = $ this-> domain. "\ r \ n ";
$ Out. = "Connection: Close \ r \ n ";
Fputs ($ fp, $ out );
While (! Feof ($ fp ))
{
$ Wh. = nl2br (fgets ($ fp, 255 ));
}
Fclose ($ fp );
Return $ wh;
}
//
// Output the status information of the current domain name
//
Function PrintSta ()
{
$ Rs = $ this-> GetInfo ();
If ($ rs = "OK") echo $ this-> domain. "Not registered! <Br/> \ r \ n ";
Else if ($ rs = "") echo "unable to query". $ this-> domain. "status! <Br/> \ r \ n ";
Else echo $ this-> domain. "registered, expiration time: $ rs <br/> \ r \ n ";
}
//
// Obtain the 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;
}
//
// Convert the month in English to a number.
//
Function MonthToNum ($ m)
{
$ M = strtolower ($ m );
For ($ I = 1; $ I <= 12; $ I ++)
{
$ Tt = mktime (2005, 0, $ I + );
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 whether the 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 "unable to query". $ sd-> domain. "status! <Br/> \ r \ n ";
Else echo $ sd-> domain. "registered, expiration time: $ rs <br/> \ r \ n ";
// Obtain the detailed whois information of the domain name
// Echo $ sd-> GetWhois ();
?>