Created
March 11, 2021 12:46
-
-
Save GeertHauwaerts/d5d254e55aaf38cabaa6bcbdf0aaef5c to your computer and use it in GitHub Desktop.
PHP - Check MX Records Against IP Bans
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 | |
$domain = 'spamdomain.com'; | |
function banMxServer($domain) { | |
$banlist = [ | |
'1.2.3.4', | |
'2.3.4.5', | |
]; | |
if (!getmxrr($domain, $mxs) || empty($mxs)) { | |
return false; | |
} | |
foreach ($mxs as $mx) { | |
$ips = gethostbynamel($mx); | |
foreach ($ips as $ip) { | |
if (in_array($ip, $banlist)) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment