whois 정보 취득하기 위한 PHP - domain.class
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 = "$domain1512";
  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;
 }
 
}
/* 
sample.php ------------------------ 
*/
<?
include_once("domain.class.php");
?>
<html>
<head>
 <title>Domain 
LookUp Example</title>
</head>
<body>
<?
$domain = new 
Domain("miniwini.com");  // .com 
//$domain = new 
Domain("miniwini.or.kr","whois.krnic.net"); // .kr 은 이렇게 
$domain->Lookup();
$info = $domain->Get();
 foreach($info as $key=>$val)
 {
  
print "$key = $val<br>";
 }
if(isset($info['whoisserver']))
{
 $domain->SetWhois($info['whoisserver']);
 $domain->Lookup();
 
 $info 
= $domain->Get();
 
 foreach($info as $key=>$val)
 {
  print 
"$key = $val<br>";
 }
}
else
{
 foreach($info as 
$key=>$val)
 {
  print "$key = $val<br>";
 }
}
?>
</body>
</html>