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 function can be used to check a domain
for any type of DNS record. 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.
If the domain does not have any DNS records, the output will be "Domain is available!". If the domain has any DNS records, the response will be "Domain is already taken".
#!/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";