KBD

Keith Devens .com

Saturday, July 4, 2009 Flag waving
That which yields, is not always weak. – Jacqueline Carey (Kushiel's Dart)
← Google AnalyticsS5: A Simple Standards-Based Slide Show System →

Daily link icon Monday, November 14, 2005

How to check an IP address against blacklists

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;
}
?>
← Google AnalyticsS5: A Simple Standards-Based Slide Show System →

Comments XML gif


Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

July 2009
SunMonTueWedThuFriSat
 1234
567891011
12131415161718
19202122232425
262728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 3 posts

Recent comments XML

new⇒Wizard's First Rule

> while it is cheesy to some​extent, I actually found it to be​pretty enjoy...

Keith: Jul 3, 6:33pm

I hate Norton Antivirus

I bought Norton 2009 and it is not​installing on my computer!!!
It​seems l...

o'neil: Jun 30, 11:44am

Generated in about 0.246s.

(Used 8 db queries)