Here's how to check an IP address against standard DNS blacklist servers, for purposes of blocking comment spam and such:
<?php
function isBlacklisted($ip){
$check = join('.',array_reverse(explode('.',$ip))).'.xbl.spamhaus.org.';
return dns_check_record($check,'A');
}
?>
dns_check_record is checkdnsrr before PHP 5.
Update: Note that for a reason unknown to me the ending period is necessary. Also, here's a multi-service version for you:
<?php
function isBlacklisted($ip){
$services = array('xbl.spamhaus.org', '...');
foreach($services as $service){
$check = join('.',array_reverse(explode('.',$ip))).".$service.";
if(dns_check_record($check,'A')) return true;
}
return false;
}
?>
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):