#native_company# #native_desc#
#native_cta#

Check Whois

By Eric Sammons
on October 8, 2001

Version: 1.0.0

Type: Function

Category: Networking

License: GNU General Public License

Description: Simple Whois availability script that includes check on .biz and .info names as well. Checks appropriate whois server depending on TLD.

<?

   /****************************************
   *     Function: CheckWhois
   *       Author: Eric Sammons, Vansam Software (www.vansam.com)
   * Date Created: 10/08/01
   *      Version: 1.0.0
   *
   *  Description: This function will check the
   *               whois database to see if a domain
   *               name is taken.
   *               Return Values:  -2 Error
   *                               -1 registered
   *                                1 unregistered
   *               
   *       Inputs: 	$strDomain - Second Level Domain name to check.
   *				$strTLD - Top Level Domain (such as .com or .info)
   *
   *                            
   *****************************************/
function CheckWhois($strDomainName, $strTLD) {      
	if ($strDomainName) { 
    // Determine the proper whois server to check 
		switch ($strTLD) {
			case "info":
	        	$server="whois.afilias.net";
				break;
			case "cc":
	        	$server="whois.enic.cc"; 
				break;
		 	case "biz":
	         	$server="whois.biz"; 
				break;
			case "com":
			case "net":
			case "org":
				$server="rs.internic.net";
				break;
			default:	
	         	return (-2); 
				break;
		}
		// Open connection to whois server to check domain name
	    $fp = fsockopen( $server, 43, &$errno, &$errstr, 10); 
	} else {
		return (-2);
	}	
	if (!$fp) { 
		return (-2); //Not able to get registration information.
	} else { 
		$FullDomain=$strDomainName.".".$strTLD;
		fputs($fp, "$FullDomainrn"); 
		// Check through response from whois server to determine availability
		while(!feof($fp)) { 
			$buf = fgets($fp,128); 
			if (ereg( "NOT FOUND", $buf) and ($strTLD=="info")) { 
				return 1;
			} elseif (ereg( "Not found", $buf) and ($strTLD=="biz")) {
				return 1;	  
			}  elseif (ereg( "No match for ", $buf)) { 
				return 1;
			}	
		} 
		fclose($fp); 
	} 
	return (-1);
} //End of CheckWhois function
?>