Skip to content

Instantly share code, notes, and snippets.

@kane-c
Created July 17, 2014 00:23
Show Gist options
  • Save kane-c/17490558a58be150ca5b to your computer and use it in GitHub Desktop.
Save kane-c/17490558a58be150ca5b to your computer and use it in GitHub Desktop.
Gets the DNS records for a given domain(s)
#!/usr/bin/env php
<?php
if ($_SERVER['argc'] < 2) {
echo 'Usage: ', basename(__FILE__), ' domain-name.com [domains...]';
die;
}
foreach ($_SERVER['argv'] as $i => $domain) {
// 0 is the script name
if (0 === $i) {
continue;
}
echo $domain . PHP_EOL . PHP_EOL;
echo implode("\t", array(
'Type',
// 'TTL',
'Target',
)), PHP_EOL;
$records = dns_get_record($domain, DNS_ALL - DNS_SOA);
foreach ($records as $record) {
$row = array(
$record['type'],
// $record['ttl'],
);
switch ($record['type']) {
case 'A':
$row[] = $record['ip'];
break;
case 'AAAA':
$row[] = $record['ipv6'];
break;
case 'MX':
$row[] = $record['pri'];
// No break
case 'NS':
case 'CNAME':
$row[] = $record['target'];
break;
case 'TXT':
$row[] = $record['txt'];
break;
default:
var_dump($record);
}
echo implode("\t", $row), PHP_EOL, PHP_EOL;
}
}
echo PHP_EOL, 'Complete', PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment