Last active
July 9, 2018 15:05
-
-
Save tdavis-ourfuture/5833093 to your computer and use it in GitHub Desktop.
Quick and dirty php command line script to check a list of domains for those that use gmail. For email nerds, fanboys and geniuses only.
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
#!/usr/bin/php | |
<?php | |
/** | |
* Checks a list of domains and outputs any that use Google. | |
* | |
* usage: php ./googlecheck.php filewithdomains | |
* | |
*/ | |
stream_set_blocking(STDIN, 0); | |
if (count($argv)<2) | |
{ | |
echo "usage: googlecheck.php [filename]\n"; | |
exit; | |
} | |
$domains = $argv[1]; | |
if (!file_exists($domains)) | |
{ | |
echo "\n'$domains' is not a valid file\nusage: googlecheck.php [filename]\n"; | |
exit; | |
} | |
$trimmed = file($domains, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); | |
if (!is_array($trimmed)) | |
{ | |
echo "\nFile does not contain list of domains.\nusage: ./googlecheck [filename]\n"; | |
exit; | |
} | |
$domains_to_check = count($trimmed); | |
echo "\nChecking ".$domains_to_check." domains for gmail...\n\n"; | |
checkGoogleArray($trimmed); | |
exit; | |
function win_getmxrr($hostname, &$mxhosts, &$mxweight=false) { | |
if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') return; | |
if (!is_array ($mxhosts) ) $mxhosts = array(); | |
if (empty($hostname)) return; | |
$exec='nslookup -type=MX '.escapeshellarg($hostname); | |
@exec($exec, $output); | |
if (empty($output)) return; | |
$i=-1; | |
foreach ($output as $line) { | |
$i++; | |
if (preg_match("/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.+)$/i", $line, $parts)) { | |
$mxweight[$i] = trim($parts[1]); | |
$mxhosts[$i] = trim($parts[2]); | |
} | |
if (preg_match('/responsible mail addr = (.+)$/i', $line, $parts)) { | |
$mxweight[$i] = $i; | |
$mxhosts[$i] = trim($parts[1]); | |
} | |
} | |
return ($i!=-1); | |
} | |
if (!function_exists('getmxrr')) { | |
function getmxrr($hostname, &$mxhosts, &$mxweight=false) { | |
return win_getmxrr($hostname, $mxhosts, $mxweight); | |
} | |
} | |
function checkGoogle($array) | |
{ | |
foreach ($array as $str) | |
{ | |
if (preg_match ('/(google|psmtp.com)/i', $str, $m)) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
function checkGoogleArray($array) | |
{ | |
foreach ($array as $domain) | |
{ | |
getmxrr($domain,$mxhosts,$mxweight); | |
if (checkGoogle($mxhosts)==true) | |
{ | |
echo "$domain\n"; | |
} | |
else | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment