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.
Thanks, but the error message already tells you what you should do. :)

But i really did not understand what to do :D

Please help.
 
0
•••
I'm not sure how to make what I am saying and what is in the error message more clear. Do this part:
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
Contact your hosting provider about the problem.

If YOU are the webmaster, then you need to contact the hosting company. If you are the hosting company, then you need to contact someone that provides you with technical support. If you are the one that provides technical support, you need to look at the server logs. If you don't know how to look at the server logs, you need to find someone that can help you with that. :)
 
0
•••
I'm not sure how to make what I am saying and what is in the error message more clear. Do this part:Contact your hosting provider about the problem.

If YOU are the webmaster, then you need to contact the hosting company. If you are the hosting company, then you need to contact someone that provides you with technical support. If you are the one that provides technical support, you need to look at the server logs. If you don't know how to look at the server logs, you need to find someone that can help you with that. :)

Thanks friend ;)
 
0
•••
Hey guys,

Came across this for an application I was brewing up that needs to process massive amounts of domain ability checks. The original check functionality which attempts to connect to the appropriate whois server couldn't handle the amount of data I was throwing at it so I resorted to checking for nameservers first. If there is nameserver information then the domain is definitely registered. If there is no nameserver information then double check by using the original code. For my application it is only imperative that I am positive that the domain is registered so the second step has not proven necessary. With this there is no need to sleep as I do not believe there is a restriction on nameserver queries. So far so good I can plug away at a pace of around 45,000 checks per hour.

Code :

Code:
$dnsRecord = @dns_get_record($domain, DNS_ANY);
                        
if( empty($dnsRecord) )
{ 
    // No nameserver info found
    // Consider double checking with original fsock code
}
else
{
    // Nameserve info found, domain is registered
}

Many thanks to Matt and all the other contributors. Hope that helps!

Mark
 
0
•••
Mark,

Genius! Doing a nameserver pre-check should speed up the operation and remove some load from nameservers. I've never been blocked, but I don't run many names at one time. A couple times a month I update some lists and each is about 1,000 domains.

I think this is a great addition to the script. I can't quickly add this to the script, would someone mind helping with this?

Also, I love this damn thing. I don't know if Matt is still folling this thread but I will try to contact him. I would like to put up a site that can host the script as open source, if it's ok with Matt.

Comments? Feedback?
 
0
•••
It would be awesome if somebody could update the code with Mark's addition. I'm not a programmer, and it would really be nice if I could get the 45k per hour checks that he's getting.
 
0
•••
I second this. It'd make for a great 'official' update :)

It would be awesome if somebody could update the code with Mark's addition. I'm not a programmer, and it would really be nice if I could get the 45k per hour checks that he's getting.
 
0
•••
Pretty sure this is what you guys/gals are after.
There may be other changes I have made I am not sure.
EDIT: I made it so it would check .org's

Code:
<?php

@set_time_limit(0);

/**
* Bulk domain availablity check script (Revision 7)		
*
* Created  by "Matthew." (up to revision 6) (45276) @ http://namepros.com / http://mattjewell.com
* Modified by "Eric"     (revision 7)       (14781) @ http://namepros.com / http://secondversion.com
*
* Feel free to modify/use however you wish, but keep credit comments in upon distribution.
*/

/**
* Changes by "Eric" (Eric Sizemore)
*
* Revision 7, October 13th, 2009
* -------------------------------------
* - Added blank index pages in the saves and inc directory.
* - Minor enhancements to the php code, to hopefully improve speed.
* - Should be valid HTML now.
*/

require_once('./inc/dnservers.php');

/**
* Saves domain status (available/taken/or invalid) to a text file.
*
* @param  string  Domain status
* @return void
*/
function save_file($status)
{
	global $filename, $domain, $extension;

	$domain = trim($domain);

	if (!($file_handle = @fopen($filename . "_$status.txt", 'a+')))
	{
		trigger_error('Cannot open or create file (chmod?)', E_USER_WARNING);
	}

	if ($status == 'invalid' AND $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);
}

/**
* Returns domain status (available/taken/or invalid).
*
* @param  string  Domain name
* @param  string  Domain status
* @return void
*/
function return_status($domain, $status)
{
	global $extension, $filename;

	$file = $filename;
	$domain = trim($domain);$buffer

	if (isset($_POST['save']))
	{
		save_file($status);
	}
	else
	{
		$color = ($status == 'available') ? '#008000' : '#FF0000';

		if ($status == 'invalid' AND $extension == 'org')
		{
			$status .= ' (.org WHOIS prevents request)';
		}
		echo "<div style=\"color: $color;\">$domain is $status!</div>\n";
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Bulk Domain Availability Check</title>
</head>

<body>

<?php

/** */
if (isset($_POST['submit']))
{
	$filename = 'saves/' . mt_rand(5, 99999999999);

	if (strlen($_POST['domains']) > 0)
	{
		$domains = preg_split("#\n#", trim($_POST['domains']), -1, PREG_SPLIT_NO_EMPTY);

		ob_start();

		echo '<h1>Checking ' . count($domains) . ' domains</h1><br />' . "\n";
		echo (isset($_POST['save'])) ? 'Preparing results, please wait...<br /><br />' . "\n" : '';

		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 AND isset($ext[".$extension"]))
			{
$domain = trim($domain);

if (gethostbynamel($domain) !== false) {

return_status($domain, 'taken');

}
else
{
					      //echo "here3";
				$server = $ext[".$extension"][0];

				if (!($sock = @fsockopen($server, 43)))
				{
					trigger_error("Error Connecting To Server: $server", E_USER_WARNING);
				}

				fputs($sock, "$domain\r\n");

				while (!feof($sock))
				{
					$buffer .= fgets($sock, 128);
				}
				fclose($sock);

				//if ($extension == 'org')
				//{
				//	echo nl2br($buffer);
				//}

				if (substr_count(strtolower($buffer), strtolower($ext[".$extension"][1])) > 0)
				{
					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.01);
		}

		@ob_end_flush();

		if (isset($_POST['save']) AND count($domains) > 0)
		{
			echo 'Check completed, your results can be found below:' . "\n";

			if (file_exists("{$filename}_available.txt"))
			{
				echo '<br /><a href="' . $filename . '_available.txt">Available domains</a>' . "\n";
			}

			if (file_exists("{$filename}_taken.txt"))
			{
				echo '<br /><a href="' . $filename . '_taken.txt">Taken domains</a>' . "\n";
			}
			else
			{
				echo '<br />0 taken domains found' . "\n";
			}

			if (file_exists("{$filename}_invalid.txt"))
			{
				echo '<br /><a href="' . $filename . '_invalid.txt">Invalid domains (could not be checked)</a>' . "\n";
			}
		}
	}
	else
	{
		echo 'You need to enter one or more domains!';
	}
}
else
{
?>
<div style="text-align: center;">
	<form action="index.php" method="post">
	<p>
		<textarea name="domains" cols="100" rows="20"></textarea><br />
		<input type="checkbox" name="save" id="save" value="save" /> <label for="save">Save results as text file?</label><br /><br />
		<input type="submit" name="submit" value="Check Availability" style="font-size: 30pt;" />
	</p>
	</form>
</div>
<?php
}
?>

</body>
</html>
 
Last edited:
1
•••
Hello!
I tried this script it works great.

Is is possible to have the domain name in output file clickable?

Eg, i checked 3 domains jkaldjwewe.com, skdhaskjdh.info, khakjsdhsad.com

Output was

Checking 3 domains

jkaldjwewe.com is available!
skdhaskjdh.info is available!
khakjsdhsad.com is available!

I want to make all domain name clickable
When user clicks on jkaldjwewe.com it will take him to say xyz.com/jkaldjwewe.com

Please can anyone here can guide me.

Regards,
Ritesh Jain
 
0
•••
oh easy to install! thank you so much!!
 
0
•••
Pretty sure this is what you guys/gals are after.
There may be other changes I have made I am not sure.
EDIT: I made it so it would check .org's

Code:
<?php

@set_time_limit(0);

/**
* Bulk domain availablity check script (Revision 7)		
*
* Created  by "Matthew." (up to revision 6) (45276) @ http://namepros.com / http://mattjewell.com
* Modified by "Eric"     (revision 7)       (14781) @ http://namepros.com / http://secondversion.com
*
* Feel free to modify/use however you wish, but keep credit comments in upon distribution.
*/

/**
* Changes by "Eric" (Eric Sizemore)
*
* Revision 7, October 13th, 2009
* -------------------------------------
* - Added blank index pages in the saves and inc directory.
* - Minor enhancements to the php code, to hopefully improve speed.
* - Should be valid HTML now.
*/

require_once('./inc/dnservers.php');

/**
* Saves domain status (available/taken/or invalid) to a text file.
*
* @param  string  Domain status
* @return void
*/
function save_file($status)
{
	global $filename, $domain, $extension;

	$domain = trim($domain);

	if (!($file_handle = @fopen($filename . "_$status.txt", 'a+')))
	{
		trigger_error('Cannot open or create file (chmod?)', E_USER_WARNING);
	}

	if ($status == 'invalid' AND $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);
}

/**
* Returns domain status (available/taken/or invalid).
*
* @param  string  Domain name
* @param  string  Domain status
* @return void
*/
function return_status($domain, $status)
{
	global $extension, $filename;

	$file = $filename;
	$domain = trim($domain);$buffer

	if (isset($_POST['save']))
	{
		save_file($status);
	}
	else
	{
		$color = ($status == 'available') ? '#008000' : '#FF0000';

		if ($status == 'invalid' AND $extension == 'org')
		{
			$status .= ' (.org WHOIS prevents request)';
		}
		echo "<div style=\"color: $color;\">$domain is $status!</div>\n";
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Bulk Domain Availability Check</title>
</head>

<body>

<?php

/** */
if (isset($_POST['submit']))
{
	$filename = 'saves/' . mt_rand(5, 99999999999);

	if (strlen($_POST['domains']) > 0)
	{
		$domains = preg_split("#\n#", trim($_POST['domains']), -1, PREG_SPLIT_NO_EMPTY);

		ob_start();

		echo '<h1>Checking ' . count($domains) . ' domains</h1><br />' . "\n";
		echo (isset($_POST['save'])) ? 'Preparing results, please wait...<br /><br />' . "\n" : '';

		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 AND isset($ext[".$extension"]))
			{
$domain = trim($domain);

if (gethostbynamel($domain) !== false) {

return_status($domain, 'taken');

}
else
{
					      //echo "here3";
				$server = $ext[".$extension"][0];

				if (!($sock = @fsockopen($server, 43)))
				{
					trigger_error("Error Connecting To Server: $server", E_USER_WARNING);
				}

				fputs($sock, "$domain\r\n");

				while (!feof($sock))
				{
					$buffer .= fgets($sock, 128);
				}
				fclose($sock);

				//if ($extension == 'org')
				//{
				//	echo nl2br($buffer);
				//}

				if (substr_count(strtolower($buffer), strtolower($ext[".$extension"][1])) > 0)
				{
					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.01);
		}

		@ob_end_flush();

		if (isset($_POST['save']) AND count($domains) > 0)
		{
			echo 'Check completed, your results can be found below:' . "\n";

			if (file_exists("{$filename}_available.txt"))
			{
				echo '<br /><a href="' . $filename . '_available.txt">Available domains</a>' . "\n";
			}

			if (file_exists("{$filename}_taken.txt"))
			{
				echo '<br /><a href="' . $filename . '_taken.txt">Taken domains</a>' . "\n";
			}
			else
			{
				echo '<br />0 taken domains found' . "\n";
			}

			if (file_exists("{$filename}_invalid.txt"))
			{
				echo '<br /><a href="' . $filename . '_invalid.txt">Invalid domains (could not be checked)</a>' . "\n";
			}
		}
	}
	else
	{
		echo 'You need to enter one or more domains!';
	}
}
else
{
?>
<div style="text-align: center;">
	<form action="index.php" method="post">
	<p>
		<textarea name="domains" cols="100" rows="20"></textarea><br />
		<input type="checkbox" name="save" id="save" value="save" /> <label for="save">Save results as text file?</label><br /><br />
		<input type="submit" name="submit" value="Check Availability" style="font-size: 30pt;" />
	</p>
	</form>
</div>
<?php
}
?>

</body>
</html>

This is supposed to be index.php, right?

Tried running this - gave me a parse error on line 69.

Any fix?
 
0
•••
This is supposed to be index.php, right?

Tried running this - gave me a parse error on line 69.

Any fix?
Just above Line 69 remove "$buffer" <--- I dont know how it got there must of been a paste gone wrong :/ lol
 
0
•••
What if we check the sub-domain of the web. like blog1.blogspot.com. can do?
 
Last edited:
0
•••
What if we check the sub-domain of the web. like blog1.blogspot.com. can do?
Not with this script. It checks the WHOIS to see if the domain is registered or not. The WHOIS won't have subdomain information. You would have to check the DNS for that.
 
0
•••
0
•••
No, I can't tell you how to do that. This thread is about the domain checking script and not about subdomain checking. You will have to find that information someplace else. Sorry.
 
0
•••
0
•••
Hey guys,

Came across this for an application I was brewing up that needs to process massive amounts of domain ability checks. The original check functionality which attempts to connect to the appropriate whois server couldn't handle the amount of data I was throwing at it so I resorted to checking for nameservers first. If there is nameserver information then the domain is definitely registered. If there is no nameserver information then double check by using the original code. For my application it is only imperative that I am positive that the domain is registered so the second step has not proven necessary. With this there is no need to sleep as I do not believe there is a restriction on nameserver queries. So far so good I can plug away at a pace of around 45,000 checks per hour.

Code :

Code:
$dnsRecord = @dns_get_record($domain, DNS_ANY);
                        
if( empty($dnsRecord) )
{ 
    // No nameserver info found
    // Consider double checking with original fsock code
}
else
{
    // Nameserve info found, domain is registered
}

Many thanks to Matt and all the other contributors. Hope that helps!

Mark


Has Anyone updated the PHP Script with this Addition? I'm looking to get 45,000 checks per hour
 
0
•••
Has Anyone updated the PHP Script with this Addition? I'm looking to get 45,000 checks per hour

You'll probably be blacklisted in about 45 seconds.
 
0
•••
Has Anyone updated the PHP Script with this Addition? I'm looking to get 45,000 checks per hour
Yes it has been done.
Have a read of the thread.

You'll probably be blacklisted in about 45 seconds.

Only if it finds names that are available.
 
0
•••
Hi Guys,
I uploaded this script but it only show me the domain is taken or not.
I need to check domain expiration date...
Can anyone help me with that ?

Thanks
 
0
•••
The best you can do, I think, is to have the output link to a whois results age via a query string. You'd still have to click on each link to see the expiry though.

Hi Guys,
I uploaded this script but it only show me the domain is taken or not.
I need to check domain expiration date...
Can anyone help me with that ?

Thanks
 
0
•••
You could no date regex something out...i.e. scrape say common date formats from the output. Google should be quite helpful with that and it'd be simple enough.
 
0
•••
someone put this on Github and I'll help contribute to the code
 
0
•••
i have bulk checker for net com biz and us..custom developed.can check up to 500k for hour. in moment add more features.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back