Skip to content

Instantly share code, notes, and snippets.

@GeertHauwaerts
Created March 11, 2021 12:46
Show Gist options
  • Save GeertHauwaerts/d5d254e55aaf38cabaa6bcbdf0aaef5c to your computer and use it in GitHub Desktop.
Save GeertHauwaerts/d5d254e55aaf38cabaa6bcbdf0aaef5c to your computer and use it in GitHub Desktop.
PHP - Check MX Records Against IP Bans
<?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