Today I wanted to check a few domains and see if they were available or already taken. I figured the best way to do this would be to check if there was any DNS records for the requested domains. I did a quick look at the functions available to me in PHP, and came across the function checkdnsrr. The checkdnsrr function can be used to check a domain for any type of DNS records. So now that I found the function to use, I wrote a simple 6 line PHP script I can use from the command line. The script takes 1 parameter, the domain name.
To use the script from the command line, you would type ./domainChecker tullyrankin.com where “tullyrankin.com” would be replaced with whatever domain you are checking. If the domain has no DNS records, the output will be “Domain is available!”. If the domain has any DNS records, the response will be “Domain is already taken”. The code for this script is below.
#!/usr/bin/php -f <?php if ($argc < 2) die("Usage: php ".basename($argv)." [domain]\n"); if (checkdnsrr($argv, "ANY")) echo "Domain is already taken\n"; else echo "Domain is available!\n";