Created
March 25, 2012 12:10
-
-
Save cballou/2193218 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // output will go to domains_found.txt in the same directory | |
| php -f domain-name-finder.php | |
| // output will go to the file specified as well as domains_found.txt in the same directory | |
| php -f domain-name-finder.php > my-output-file.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * 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." . PHP_EOL); | |
| fwrite($s, $domain . PHP_EOL); | |
| $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 array of all available domains found from the $output array | |
| $available = array(); | |
| $l = count($domains) - 1; | |
| // check availability of all combinations | |
| foreach ($output as $domain) { | |
| if (checkDomainAvailability($domains[rand(0, $l)], $domain.".com")) { | |
| echo $domain.".COM" . PHP_EOL; | |
| $available[] = $domain . ".COM"; | |
| } | |
| } | |
| // store the matching domains in a file relative to this one | |
| file_put_contents('./domains_found.txt', implode(PHP_EOL, $available)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment