There are numerous sites for finding available .COM domain names. Generally, these sites will not turn up the kind of results you are actually looking for when trying to find the perfect domain for your startup, personal site, or business. With the following simple snippet of code you will be able to generate a list of all available two word combinations for a supplied list of keywords. It can be ran from the command line and can output a txt file of all matching domains. I hope you find this as useful as I have.
/**
* Simple function for checking the domain availability
* of a .COM.
*
* @param string $whois The whois host
* @param string $domain The domain to check
*/
function checkDomainAvailability($whois, $domain) {
$s = fsockopen($whois, 43) or die("An error occurred attempting to connect to the whois server $whois\n");
fwrite($s, "$domain\r\n");
$result = '';
while(!feof($s)) $result .= fgets($s, 128);
fclose($s);
if (preg_match('/(No match|NOT FOUND)/i', $result)) return true;
return false;
}
/**
* A function to find all two word combinations from a user
* specified list of words. This can be heavily modified
* to try more variations of words in addition to trying
* with hyphens.
*
* @param array $array An array of words
* @param array $output An array of two word combinations from the first parameter array
*/
function findCombinations($array, &$output) {
if (!empty($array) && count($array) > 1) {
$word = array_pop($array);
foreach ($array as $val) {
$output[] = $val . $word;
$output[] = $word . $val;
}
findCombinations($array, $output);
}
}
// an array of whois domains to randomly pick from to avoid the banhammer
$domains = array("whois.nsiregistry.net", "whois.crsnic.net", "whois.verisign-grs.com");
// an array of user chosen words to test for available combinations
$words = array('testing','site','tested','asdf','foobar');
// array combination of storage
$output = array();
// find all combinations
findCombinations($words, $output);
// a storage string of all available domains found from the $output array
$available = '';
$l = count($domains) - 1;
// check availability of all combinations
foreach ($output as $domain) {
if (checkDomainAvailability($domains[rand(0, $l)], $domain.".com")) {
echo $domain.".COM\n";
$available .= $domain.".COM\n";
}
}
// store the matching domains in a file relative to this one
file_put_contents('./domains_found.txt', $available);
Simply modify the $words array, save the code as finddomains.php, and run the following command in your console to execute:
php -f finddomains.php
It’s worth noting that you should keep the keyword list fairly short as to not DoS the whois servers. This is mainly due to the fact the basic implementation has no timeout/sleep between calls. It is also recommended that you search for a greater number of public whois servers as to alleviate the number of requests per server when iterating over a large list of combinations.
Happy hunting and please let me know how things turn out!
Leave a Reply