<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ankur&#039;s PHP and Javascript blog &#187; WHOIS</title>
	<atom:link href="http://www.ankur.com/blog/tag/whois/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ankur.com/blog</link>
	<description>PHP and javascript blog</description>
	<lastBuildDate>Tue, 10 Nov 2009 14:28:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Domain name WHOIS query using PHP</title>
		<link>http://www.ankur.com/blog/90/php/domain-whois-query-php/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=domain-whois-query-php</link>
		<comments>http://www.ankur.com/blog/90/php/domain-whois-query-php/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 18:01:17 +0000</pubDate>
		<dc:creator>Ankur Motreja</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WHOIS]]></category>

		<guid isPermaLink="false">http://www.ankur.com/blog/?p=90</guid>
		<description><![CDATA[This post is about a PHP class which allows you to check if a domain name is available or not using WHOIS servers. The class simply opens a socket connection to the WHOIS server and passes the domain name to check for. Based on the available string you provide, it checks if the domain name [...]


Related posts:<ol><li><a href='http://www.ankur.com/blog/106/php/resume-http-downloads-php-curl-fsockopen/' rel='bookmark' title='Permanent Link: Resume HTTP downloads in PHP using cURL or fsockopen'>Resume HTTP downloads in PHP using cURL or fsockopen</a></li><li><a href='http://www.ankur.com/blog/68/php/curl-wrapper-class-cli-php-extension-support/' rel='bookmark' title='Permanent Link: cURL wrapper class with executable and PHP extension support'>cURL wrapper class with executable and PHP extension support</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>This post is about a PHP class which allows you to check if a domain name is available or not using WHOIS servers. The class simply opens a socket connection to the WHOIS server and passes the domain name to check for. Based on the available string you provide, it checks if the domain name is available or not.</p>
<p><span id="more-90"></span> The PHP code is below:</p>
<pre class="brush: php;">
class WhoisQuery {

	var $whoisServer;
	var $availableString;
	var $domainName;
	var $extension;

	function checkAvailability() {

		$output = &quot;&quot;;

		if(($connection = @fsockopen($this-&gt;whoisServer, 43, $errno, $errstr, 15)) == false){
			return array(&quot;errno&quot; =&gt; $errno, &quot;errstr&quot; =&gt; $errstr);
		}

		fputs($connection, $this-&gt;domainName . $this-&gt;extension . &quot;\\r\\n&quot;);

		while(!feof($connection)) {
			$output .= fgets($connection, 4096);
		}

		fclose($connection);

		if (strlen($output) == 0) {
			return array(&quot;errno&quot; =&gt; 0, &quot;errstr&quot; =&gt; &quot;no output&quot;);
		}

		if ( is_integer( strpos($output, $this-&gt;availableString) ) ) {
			return true;
		} else {
			return false;
		}

	}

}
</pre>
<p>You can use it as shown below:</p>
<pre class="brush: php;">
$domainAvailability = new WhoisQuery;
$domainAvailability-&gt;whoisServer = &quot;whois.verisign-grs.com&quot;;
$domainAvailability-&gt;availableString = &quot;No match for&quot;;
$domainAvailability-&gt;domainName = &quot;ankur&quot;;
$domainAvailability-&gt;extension = &quot;.com&quot;;

$result = $domainAvailability-&gt;checkAvailability();

if ($result === true) {
	echo &quot;available&quot;;
} elseif ($result === false) {
	echo &quot;not available&quot;;
} else {
	echo $result[&quot;errstr&quot;];
}
</pre>
<p>We pass it the WHOIS server in whoisServer, the string that should be present in the response if the domain name is available in availableString, the first part of the domain name in domainName and the extension in extension. $result is an array with keys errno and errstr if an error occurred, true if the domain name is available and false if it isn&#8217;t.  Please note that WHOIS servers may limit the frequency of queries you perform. This has not been handled in the class.</p>
<p>You can connect to a WHOIS server manually using a program like <a rel="nofollow" rel="nofollow" href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html" target="_blank">PuTTY </a>. Enter the WHOIS server name in the Host Name section and use the port 43. Type in the full domain name (example, ankur.com) and the response will be the WHOIS data.</p>
<p>Now, how do you find WHOIS servers for the extension you would like to check ? whois-servers.net provides some aliases for whois servers. For example, use com.whois-servers.net to connect to the .com WHOIS server. You can also check the <a rel="nofollow" rel="nofollow" href="http://www.iana.org/domains/root/db/" target="_blank">IANA&#8217;s Database of Top Level Domains</a> to see if it contains WHOIS server information for your extension.</p>


<p>Related posts:<ol><li><a href='http://www.ankur.com/blog/106/php/resume-http-downloads-php-curl-fsockopen/' rel='bookmark' title='Permanent Link: Resume HTTP downloads in PHP using cURL or fsockopen'>Resume HTTP downloads in PHP using cURL or fsockopen</a></li><li><a href='http://www.ankur.com/blog/68/php/curl-wrapper-class-cli-php-extension-support/' rel='bookmark' title='Permanent Link: cURL wrapper class with executable and PHP extension support'>cURL wrapper class with executable and PHP extension support</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ankur.com/blog/90/php/domain-whois-query-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
