Location: PHPKode > scripts > Expired Domain Class > expired-domain-class/domain.class.php
<?

/*******************************************************************************

													--  Expired Domain Class  --
     
		 This class allows you to query the whois server and obtain information
		 about who owns a particular domain, when that domain expires, and other
		 information.
		 
		 Author			 :	Steven Pratt
		 Email			 :	hide@address.com
		 License		 :	This is distributed and intended for free use as per the
		 						 		GNU Public License.  The only	stipulation is that this 
										header must remain intact.  For a copy of the GPL, please
										go to http://www.gnu.org/licenses/gpl.txt
													
*******************************************************************************/

class Domain
{

 var $_whois_server;
 var $_ip_address;
 var $_time_out;
 var $_port_num;
 
 var $_results;
 
 function Domain($ip_address, $whois_server="")
 {
  $this->_domain_name = $ip_address;
	$this->_port_num    = 43;
	$this->_time_out    = 30;
	if($whois_server == ""){ $this->_whois_server = "whois.internic.net"; }
	else{ $this->_whois_server = $whois_server; }
 }

 function SetWhois($server)
 {
  $this->_whois_server = trim($server);
 }
 
 function Lookup()
 {
  $host     = $this->_whois_server;
	$port_num = $this->_port_num;
	$time_out = $this->_time_out;
	$domain   = $this->_domain_name;
	
	$feed_back = "";
	
  if($who_sock = fsockopen($host, $port_num, $errno, $errstr, $time_out))
	{
	 $feeder = "$domain\015\012";
	 fputs($who_sock, $feeder);
	 while(!feof($who_sock))
	 {
	  $feed_back .= fgets($who_sock, 128) . "\n";
	 }
	 fclose($who_sock);
	}
	else
	{
	 print "Cannot connect to [$host] for query.";
	 exit;
	}
	$this->_results = $feed_back;
	//  The line below is a sanity checker...
	//  print $feed_back;
 }
 
 function Get()
 {
  $res     = $this->_results;
	$results = array();
	
	$fn = preg_match('/domain.+?:(.+?)\\n/i', $res, $full_name);
	$cr = preg_match('/creat.+?:(.+?)\\n/i', $res, $created);
	$ex = preg_match('/expir.+?:(.+?)\\n/i', $res, $expires);
	$up = preg_match('/updated.+?:(.+?)\\n/i', $res, $updated);
	$wh = preg_match('/whois.+?:(.+?)\\n/i', $res, $whois);
	$re = preg_match('/referral.+?:(.+?)\\n/i', $res, $referral);
	$ns = preg_match_all('/name ser.+?:(.+?)\\n/i', $res, $name_server);
	
	if($fn) $results['fullname'] = $full_name[1];
	if($cr) $results['created'] = $created[1];
	if($ex) $results['expires'] = $expires[1];
	if($up) $results['updated'] = $updated[1];
	if($wh) $results['whoisserver'] = $whois[1];
	if($re) $results['nameserver'] = $name_server[1];
	if($ns) $results['referral'] = $referral[1];
	
	return $results;
 }
 
}
Return current item: Expired Domain Class