Login   Register  
PHP Classes
elePHPant
Icontem

File: clsWhois.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of chris  >  Whois  >  clsWhois.php  >  Download  
File: clsWhois.php
Role: ???
Content type: text/plain
Description: The source
Class: Whois
Author: By
Last change:
Date: 12 years ago
Size: 2,060 bytes
 

Contents

Class file image Download
<?
/*
************************************************************************
*  Sloppycode.net All rights reserved.
*
* This is a standard copyright header for all source code appearing
* at sloppycode.net. This application/class/script may be redistributed,
* as long as the above copyright remains intact. 
* Comments to sloppycode@sloppycode.net
************************************************************************
*/

/**
 * @title Whois wrapper for most global TLDs
 * @author C.Small
 * @version 1.4 - Timeout and whois_server properties added.
 * @version 1.3 - Temporary fix for .name,.pro domains
 * @version 1.2 - Error catching for .tv domains
 * @version 1.1 - Converted to php
 * @version 1.0 - Perl version [http://www.sloppycode.net/sloppycode/Perl[CGI]/s29.html]
*/

Class Whois
{
	var $whois_server;
	var $timeout = 30;

	function lookup($domain)
	{
		$result = "";
		$parts  = array();
		$host   = "";
		
		// .tv don't allow access to their whois
		if (strstr($domain,".tv"))
		{
			$result = "'.tv' domain names require you to have an account to do whois searches.";
		// New domains fix (half work, half don't)
		} elseif (strstr($domain,".name") || strstr($domain,".pro") >0){
			$result = ".name,.pro require you to have an account to do whois searches.";
		} else{
			if (empty($this->whois_server))
			{
				$parts    = explode(".",$domain);
				$testhost = $parts[sizeof($parts)-1];
				$whoisserver   = $testhost . ".whois-servers.net";
				$this->host     = gethostbyname($whoisserver);
				$this->host     = gethostbyaddr($this->host);
			
				if ($this->host == $testhost)
				{
					$this->host = "whois.internic.net";
				}
				flush();
			}
			$whoisSocket = fsockopen($this->host,43, $errno, $errstr, $this->timeout);
			
			if ($whoisSocket)
			{
				fputs($whoisSocket, $domain."\015\012");
				while (!feof($whoisSocket))
				{
					$result .= fgets($whoisSocket,128) . "<br>";
				}
				fclose($whoisSocket);
			}
		}
		return $result;
	}
}
?>