This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dc.php
47 lines (47 loc) · 1.63 KB
/
dc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/php -q
<?php
echo "https://github.com/adamziaja/dns-check\n";
echo "(C) 2013 Adam Ziaja <[email protected]> http://adamziaja.com\n";
require_once('Net/DNS2.php'); // http://code.google.com/p/netdns2/
$domain = $argv[1];
$todo = check_dns($domain);
function check_dns($domain) {
$todo = array();
$dns_records = dns_get_record($domain, DNS_NS);
if (!count($dns_records)) {
echo "\n\033[1;33mhost $domain not found\033[0m\n";
}
$dns_servers = array();
foreach ($dns_records as $dns_record) {
foreach (gethostbynamel($dns_record['target']) as $ip) { // Round-robin DNS
array_push($dns_servers, $ip);
}
}
foreach ($dns_servers as $dns_server) {
echo "\n\033[1;32m" . $dns_server . ' (' . gethostbyaddr($dns_server) . ") AXFR $domain\033[0m\n";
$result = NULL;
$r = new Net_DNS2_Resolver(array('nameservers' => array($dns_server)));
try {
$result = $r->query($domain, 'AXFR');
} catch (Net_DNS2_Exception $e) {
echo "\033[1;31m::query() failed: ", $e->getMessage(), "\033[0m\n";
}
if ($result) {
foreach ($result->answer as $rr) {
if (preg_match('/ IN NS /i', $rr) && !preg_match("/^$domain/i", $rr)) {
echo "\033[1;35m$rr\033[0m\n";
$ns = rtrim(reset(explode(' ', $rr)), '.');
array_push($todo, $ns);
} else {
echo "$rr\n";
}
}
}
}
$todo = array_unique($todo);
return $todo;
}
foreach ($todo as $domain_axfr) {
check_dns($domain_axfr);
}
?>