Last active
June 24, 2020 03:31
-
-
Save kiler129/6c0f67c81e0f584193be to your computer and use it in GitHub Desktop.
This tool can be used to verify domains in Swot project (https://github.com/leereilly/swot) by checking A/AAAA and MX records for them. It's horribly written in 10 minutes, but works ;)
This file contains 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 | |
define('DOMAINS_DIRECTORY', 'lib/domains/'); | |
function path2Domain($path, $prefix = DOMAINS_DIRECTORY) | |
{ | |
$prefixPos = strpos($path, $prefix); | |
if ($prefixPos !== 0) { | |
throw new InvalidArgumentException('Path does not begin with given prefix'); | |
} | |
$path = substr($path, strlen($prefix), -4); //Removes prefix & extension | |
$pathParts = array_reverse(explode('/', $path)); | |
return implode('.', $pathParts); | |
} | |
function getDomainStatus($domain) | |
{ | |
$records = dns_get_record($domain, DNS_A + DNS_AAA + DNS_MX); | |
if ($records === false) { | |
return false; | |
} | |
$ip = 0; | |
$mx = 0; | |
foreach ($records as $record) { | |
if ($record['type'] === 'A' || $record['type'] === 'AAAA') { | |
$ip++; | |
} elseif ($record['type'] === 'MX') { | |
$mx++; | |
} | |
} | |
return ['ip' => $ip, 'mx' => $mx]; | |
} | |
$directory = new RecursiveDirectoryIterator(DOMAINS_DIRECTORY); | |
$iterator = new RecursiveIteratorIterator($directory); | |
$regex = new RegexIterator($iterator, '/^.+\.txt$/i', RecursiveRegexIterator::GET_MATCH); | |
foreach ($regex as $path) { | |
$domain = path2Domain($path[0]); | |
echo $domain . " - "; | |
$records = getDomainStatus($domain); | |
if ($records === false) { | |
echo "DNS ERROR!\n"; | |
continue; | |
} | |
$isError = false; | |
if ($records['ip'] === 0) { | |
echo "[Missing website] "; | |
$isError = true; | |
} | |
if ($records['mx'] === 0) { | |
echo "[Missing MX] "; | |
$isError = true; | |
} | |
if (!$isError) { | |
echo "OK"; | |
} | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment