Dynadot

PHP: Bulk domain availability check!

Spaceship Spaceship
Watch
PHP: Bulk domain availability check! [UPDATED]

This is something i was going to start however i don't really have time, so i have whipped up a quick script for you guys to use on your own site or just for personal use.

The script has been tested quickly tonight as i want to go to bed lol. I hope it is of some use.

Demo: Now offline sorry.


UPDATED CODE (Revision 6): (18/02/07)


Download everything here!

.ORG support removed due to a block from the WHOIS server (PIR)

- .pt support fixed!

- Added "save results as text file" feature - requested.

- Code shortened

- Added .in support
- Bug fixes

- Added .tv domain support - requested

- Other bug fixes (again ;))

- Will now output result before checking next domain (much faster)
- Added .mobi support - requested

- Other bug fixes

PHP:
<?php
set_time_limit(0);
ob_start();
/* 	--------	Bulk domain availablity check script (Revision 4) ------------		
[																					
[ 	Created by "Matthew." (#45276) @ http://namepros.com / http://toomanylines.com		
[	Feel free to modify/use however you wish,										
[	but keep credit comments in upon distribution.								
*/

include 'inc/dnservers.php';

function save_file($status) 
{
	global $filename, $domain, $extension;
	
	$domain = trim($domain);
	
	$file_handle = fopen($filename . "_$status.txt", 'a+') or trigger_error('Cannot open or create file (chmod?)', E_USER_WARNING);
	
	if($status == 'invalid' && $extension == 'org') { $status .= ' (.org WHOIS prevents request)'; }
				
	if(!fwrite($file_handle, $domain . " is $status\n"))
	{
		trigger_error('Results for ' . $domain . ' could not be written.', E_USER_WARNING);
	}
	
	fclose($file_handle);	
}

function return_status($domain, $status)
{	
	global $extension, $filename;

	
	$file = $filename;
	$domain = trim($domain);
	
	if(isset($_POST['save']))
	{
			save_file( $status );
	}
	else
	{	
		$color = ($status == 'available') ? 'green' : 'red';
		if($status == 'invalid' && $extension == 'org') { $status .= ' (.org WHOIS prevents request)'; }	
			
		echo "<div style=\"color: $color\">$domain is $status!</div>";
	}
}	
	
if(isset($_POST['submit']))
{
	$filename = 'saves/' . mt_rand(5, 9999999999);
		
	if(strlen($_POST['domains']) > 0)
	{

		$domains = explode("\n", $_POST['domains']);
		
		echo '<h1>Checking ' . count($domains) . ' domains</h1><br />';
		echo (isset($_POST['save'])) ? 'Preparing results, please wait...<br /><br />' : null;
		
		foreach($domains as $domain)
		{
			unset($buffer); // clean buffer - prevents problems
					
			// (replaced str_replace)	
			preg_match('@^(http://www\.|http://|www\.)?([^/]+)@i', $domain, $matches);
			$domain = $matches[2];
			
			$tld = explode('.', $domain, 2);
			$extension = strtolower(trim($tld[1]));
			
			if(strlen($domain) > 0 && array_key_exists('.' . $extension, $ext))
			{
				$server = $ext['.' .$extension][0];
				
				$sock = fsockopen($server, 43) or die('Error Connecting To Server:' . $server);
				fputs($sock, "$domain\r\n");
				
				while( !feof($sock) )
				{
				  	$buffer .= fgets($sock,128);
				}
			
				fclose($sock);
				if($extension == 'org') echo nl2br($buffer);
				
				if(eregi($ext['.' . $extension][1], $buffer)) { return_status($domain, 'available'); }
				
				else { return_status($domain, 'taken'); }
			}
			else
			{
				if(strlen($domain) > 0)	 { return_status($domain, 'invalid'); }
			}
		
			ob_flush(); // output before checking next domain
			flush();
			sleep(0.1);
		}
		
		if(isset($_POST['save']) && count($domains) > 0)
		{
			echo 'Check completed, your results can be found below:';
		
			if(file_exists($filename . '_available.txt'))
			{
				echo '<br /><a href="' . $filename . '_available.txt">Available domains</a>';
			}
			
			if(file_exists($filename . '_taken.txt'))
			{
				echo '<br /><a href="' . $filename . '_taken.txt">Taken domains</a>';
			}
			else
			{
				echo '<br />0 taken domains found';
			}
			
			if(file_exists($filename . '_invalid.txt'))
			{
				echo '<br /><a href="' . $filename . '_invalid.txt">Invalid domains (could not be checked)</a>';
			}
		}	
	}
	else
	{
		echo 'You need to enter one or more domains!';
	}
} 
else
{
	?>
<div style="text-align: center">
	<form action="index.php" method="post">
		<textarea name="domains" cols="100" rows="20"></textarea>
		<br /><input type="checkbox" name="save" value="save" /> Save results as text file?<br />
		<br /><input type="submit" name="submit" value="Check Availability" style="font-size: 30pt;" />
		
	</form>
</div>
	<?php
}
?>


Instructions:

Unzip, Upload, CHMOD "saves" to 777, use!



Supported extensions are:

.com
.net
.biz
.info
.co.uk
.co.ug
.or.ug
.nl
.tv
.mobi
.in

.ro
.com.au
.ca
.org.uk
.name
.us
.ac.ug
.ne.ug
.sc.ug
.ws
.be
.com.cn
.net.cn
.org.cn
.no
.se
.nu
.com.tw
.net.tw
.org.tw
.cc
.pl
.pt

It is not coded well but this was started very early in the morning so i have an excuse lol. It works so hey ;)

Enjoy.
 
Last edited:
17
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
To try and get more queries per TLD, you could implement my whois server class, which selects a random server for the requested TLD.
 
0
•••
Matthew. said:
It makes a query to the WHOIS server which counts as...well....one query. To truly check availability you need to take the response from the WHOIS server not just open connection to the domain (otherwise when sites are down they would show as available and so on)

Thanks, i think the save to text option didn't work with large list - hangs before showing the download list links. But with that option unchecked, it seems to be working. :-/
 
Last edited:
0
•••
touchring said:
Thanks, i think the save to text option didn't work with large list. Unchecked, it seems to be working. :-/

Quite probable lol. Like I and others have said, it's ribbled with bugs...threw it together pretty quickly and to be honest the amount of php I knew back then left a lot to be desired :) I will update it as promised when I find time :D

Mikor, thanks for that, I hadn't seen your post before. If I had know about that data before I would have used it - it's a new discovery to me and will no doubt come in handy! :tu:
 
0
•••
Matthew. said:
Quite probable lol. Like I and others have said, it's ribbled with bugs...threw it together pretty quickly and to be honest the amount of php I knew back then left a lot to be desired :) I will update it as promised when I find time :D


Thanks, i found out that even though it got stuck at the "Preparing results, please wait..." stage, the files have been created under \save folder.
 
0
•••
wow. Exactly what I was looking for. Thanks!
 
0
•••
Thanks a lot.
Amazing script.
 
0
•••
this is one good freeware!. thanks for sharing!.

+rep for you!
 
0
•••
thanks a lot, however it doesnt seem to work properly with .co.uk domains
 
0
•••
It doesn't seem to work properly for dot org. I'm being blocked by whois.publicinterestregistry.net if i check more than a few domains. Is there a way around it? I mean, can i add some pause interval?

Thanks again for the great script. :)
 
0
•••
heavy whois lookups?

Can I just make comment? - don't mean to hijack your thread - you should not be using whois lookups to bulk check domain availability - unless you really need all that WHOIS info.

there are better , faster , more network friendly ways

1. for example run your domains through a simple dns check first - if there are dns servers showing , the domain must be registered (reverse not always true). for those with mac osx / linux :

[pbg42:~/Documents] paul% host -t ns nonexistantdomains.com
Host nonexistantdomains.com.lan not found: 3(NXDOMAIN)
[pbg42:~/Documents] paul% host -t ns takendomains.com
takendomains.com name server ns1.hozt.com.
takendomains.com name server ns2.hozt.com.

You can batch this easily with:

foreach var (`cat mylistofdomains.txt`)
host -t ns $var >> dnscheckresults.txt
sleep 1
end

the sleep is there to stop the script from going into meltdown
there are no limits with DNS lookups AFAIK

2. Or for lists with up to 500 keywords at a time of course just use a common bulk availablility check like the one at www.cheapnames.com (under bulk reg)

You can cut/paste and check thousands in a few minutes as cheapnames/godaddy/wwd (and other registrars) maintain their own lists of availability which give near instant results.

dax
 
Last edited:
1
•••
Heres my current (modded) copy. It has extra domain options such as LL-L and more, and several new domain extensions. I'm also making a modification to allow you to exclude certain letters...will release that bit at a later date.

PHP:
<?php
/*

SCRIPT CREATED BY MATTHEW @ NAMEPROS.COM -- MODDED BY RICKM @ NAMEPROS.COM

ENJOY!

*/
?>

<form action=available.php method=post>
<table>
<tr>
  <td class=bordered2 width=150>Type:</td>
  <td class=bordered2 width=150>Limit</td>
  <td class=bordered2 width=150>Extension</td>
</tr>
<tr>
  <td class=bordered2>
  <SELECT NAME="type" class=bordered2>
    <option value="LLL">LLL</option>
    <option value="LLLL">LLLL</option>
    <option value="LLLLL">LLLLL</option>
    <option value="LLLLLL">LLLLLL</option>
    <option value="NNN">NNN</option>
    <option value="NNNN">NNNN</option>
    <option value="NNNNN">NNNNN</option>
    <option value="NNNNNN">NNNNNN</option>
    <option value="L-L">L-L</option>
    <option value="N-N">N-N</option>
    <option value="LNL">LNL</option>
    <option value="LLN">LLN</option>
    <option value="NLL">NLL</option>
    <option value="LL-L">LL-L</option>
    <option value="L-LL">L-LL</option>
    <option value="L-L-L">L-L-L</option>
    <option value="LLNN">LLNN</option>
    <option value="LLLN">LLLN</option>
    <option value="LNNN">LNNN</option>
  </SELECT></td>
  <td class=bordered2><input type=text name=x class=camo size=6 value=250></td>
  <td class=bordered2>
  <SELECT NAME="ext" class=bordered2>
    <option value="COM">.COM</option>
    <option value="US">.US</option>
    <option value="NET">.NET</option>
    <option value="ORG">.ORG</option>
    <option value="BIZ">.BIZ</option>
    <option value="INFO">.INFO</option>
    <option value="CO.UK">.CO.UK</option>
    <option value="IN">.IN</option>
  </SELECT></td>
</tr>
<tr>
  <td class=bordered2 colspan=3><input type=submit value=Scan name=submit class=cloakedbutton></td>
</tr>
</table>
</form>

<?php

if(isset($_POST['submit'], $_POST['type']))
{
  function checkdomain($xserver, $xdomain)
  {
    $sock = @fsockopen($xserver,43) or die("Error connecting to whois server.");
    fputs($sock,"$xdomain\r\n");
    
    $result = '';
    
    while(!feof($sock))
    {
      $result .= fgets($sock,128);
    }
    fclose($sock);
    
    if(eregi("No match", $result) || eregi("NOT FOUND", $result))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  // Function
  $chars = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");
    //$chars = array("a","b","c","d","e","f","g","h","i","l","m","n","o","p","r","s","t");

  $type = trim(strip_tags($_POST['type']));
  $ext = trim(strip_tags($_POST['ext']));
  $x = intval(trim(strip_tags($_POST['x'])));

echo "<font size=2><br />\n";

  $i = 1;

      
//echo'<table border = "1"><tr bgcolor="#E6FFCC">';
  while($x >= $i)
  {
    ///////////////////////////////////////////////////////////////////////////////
    // Here is where we generate a random string of 3 in the format XXX
    // This can be changed easily to the format LLN with this code instead:
    ///// $current = $chars[rand(0,25)].$chars[rand(0,25)].rand(0,35);
    // Or to L-N with this code:
    ///// $current = $chars[rand(0,25)]."-".rand(0,9);
    // Mix and match. Get what you're looking for! :P
    
    switch($type)
    {
      case 'L-L':
           $current = $chars[rand(0,25)]."-".$chars[rand(0,25)];
           break;
      case 'N-N':
           $current = $chars[rand(26,35)]."-".$chars[rand(26,35)];
           break;
      case 'NNN':
           $current = $chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)];
           break;
      case 'NNNN':
           $current = $chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)];
           break;
      case 'NNNNN':
           $current = $chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)];
           break;
      case 'NNNNNN':
           $current = $chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)];
           break;
      case 'LNL':
           $current = $chars[rand(0,25)].$chars[rand(26,35)].$chars[rand(0,25)];
           break;
      case 'LLN':
           $current = $chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(26,35)];
           break;
      case 'NLL':
           $current = $chars[rand(26,35)].$chars[rand(0,25)].$chars[rand(0,25)];
           break;
      case 'LLL':
           $current = $chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)];
           break;
      case 'LL-L':
           $current = $chars[rand(0,25)].$chars[rand(0,25)]."-".$chars[rand(0,25)];
           break;
      case 'L-LL':
           $current = $chars[rand(0,25)]."-".$chars[rand(0,25)].$chars[rand(0,25)];
           break;
      case 'L-L-L':
           $current = $chars[rand(0,25)]."-".$chars[rand(0,25)]."-".$chars[rand(0,25)];
           break;
      case 'LLLL':
           $current = $chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)];
           break;
      case 'LLLLL':
           $current = $chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)];
           break;
      case 'LLLLLL':
           $current = $chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)];
           break;
      case 'LLNN':
           $current = $chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(26,35)].$chars[rand(26,35)];
           break;
      case 'LLLN':
           $current = $chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(26,35)];
           break;
      case 'LNNN':
           $current = $chars[rand(0,25)].$chars[rand(26,35)].$chars[rand(26,35)].$chars[rand(26,35)];
           break;

      default:
             $current = $chars[rand(0,25)].$chars[rand(0,25)].$chars[rand(0,25)];
    }

    ///////////////////////////////////////////////////////////////////////////////
    // Here is where we start checking domains
    // Feel free to add/remove domains or change whois servers
    
    switch($ext)
    {
      case 'COM':
      case 'NET':
            $registry = "whois.nsiregistry.net";
            break;
      case 'ORG':
            $registry = "whois.pir.org";
            break;
      case 'INFO':
            $registry = "whois.afilias.net";
            break;
      case 'BIZ':
            $registry = "whois.biz";
            break;
      case 'US':
            $registry = "whois.nic.us";
            break;
      case 'CO.UK':
            $registry = "whois.nic.uk";
            break;
      case 'IN':
            $registry = "whois.inregistry.net";
            break;
      default:
              $registry = "whois.nsiregistry.net";
    }
	
    if(checkdomain($registry, $current.'.'.$ext))
    {
    	
    	
      
      

        echo strtoupper($current)." . ".$ext."<br />";
     
      
      $i++;
      

    }    
    ob_flush();
    flush();
  }
  echo "</font>";
}

?>
 
Last edited:
0
•••
Thanks a million.
Waiting for the next release with option to exclude letters.
 
0
•••
bbalegere said:
Thanks a million.
Waiting for the next release with option to exclude letters.

just modify the line:

$chars = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
"0","1","2","3","4","5","6","7","8","9");


to whatever letters you want , for now.
 
Last edited by a moderator:
0
•••
So if you remove the letters it will skip those in the list?
 
0
•••
You may have to adjust the "rand" part too, as it scans each part of the array based on its location (I.E 1 = "a", 2 = "b", 27 = "0" etc)

The one I'm doing will have some sort of checkbox list that lets you de-select the ones to display....quite easy to make. I'll probably release it over the weekend.
 
0
•••
PHP:
$chars = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");
PHP:
$chars = array_merge(range('A', 'Z'), range(0,9));

:tu:
 
Last edited:
0
•••
ok, I pretty much have no clue with either one of you are saying so I will grab the new one once you finish it, lol.

Thanks.
 
0
•••
0
•••
Hello, I did not read the whole thread, is this working on .be without being banned with static IP ?

Cheers
 
0
•••
This script used to check thousands of names without a problem. Lately I've been receiving the error below after only a few hundred. Have I been blocked and does anyone have another reliable whois server for .com lookups?

Warning: fsockopen() [function.fsockopen]: unable to connect to whois.crsnic.net:43 in /home/index.php on line 79
Error Connecting To Server:whois.crsnic.net

-Bill
 
0
•••
This script isn't working for me. I download it, unzip it, upload it to my server, then change the permissions to 777, then go to my site to check it out and it gives me this error message:

Warning: fsockopen(): unable to connect to whois.crsnic.net:43 in /home/content/R/i/c/joe483726/html/listcombo/download/index.php on line 79
Error Connecting To Server:whois.crsnic.net

What am I doing wrong? I must be doing something wrong because it works perfectly fine on your demo site still, but not when I attempt to do it.
 
0
•••
Well, since nobody could answer why the script wasn't working for me, I did some research and here's why the script won't work for me. It's because I am using Godaddy which doesn't allow outgoing connections to whois unless I get a dedicated server which I'm not about to do simply for this script to run. So, there it is. This sucks.
 
0
•••
dude, its all good. download some localhost php server (like WAMP or XAMPP) and run it there... you don't have to be worry about any stupid settings and even if you do get banned by the whois servers for mass queries, the only downside will be you won't be able to run the script from your own computer.

but what are proxies for?
 
0
•••
Would like to know more about Wamp or xampp

nasaboy007 said:
dude, its all good. download some localhost php server (like WAMP or XAMPP) and run it there

If I do that, will I be hosting the script from my computer and have to leave my computer on all the time or how does that work? Basically, does it turn my computer into the server?
 
0
•••
slipknotpsychoman said:
Basically, does it turn my computer into the server?
yes
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back