KBD

Keith Devens .com

Tuesday, December 2, 2008 Flag waving
"To know what *would* have happened, child?" said Aslan. "No. Nobody is ever told that." – C.S. Lewis (Aslan, in Prince Caspian, Chapter 10)
← 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)
:

December 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



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

Recent comments XML

new⇒Perl 6 1.0 in March?

Doh, my mistake. I'm aware of the​relation between Parrot and Rakudo​but I'...

Keith: Dec 2, 1:03am

Free image hosting sites

Well, TinyPic has this in its​FAQ:

> Images and videos is in​your accoun...

Keith: Dec 1, 1:13am

Join a NameValueCollection into a querystring in C#

Well with a lamba expression, this​is what I came up​with:

?!code:csharp...

Gustaf Lindqvist: Nov 30, 4:38pm

Why no generic OrderedDictionary?

Check​http://www.codeproject.com/KB/recip​es/GenericOrderedDictionary.aspx?d...

Gabrielk: Nov 27, 6:57am

WhatIsMyIP.com

http://www.thesysteminfo.com is​another good alternate to​whatismp.com... I...

Kripz: Nov 26, 8:51pm

Girls, please don't get breast implants

Actually I think it's sweet when a​man loves a woman whether she's big​or n...

218.186.12.228: Nov 26, 9:40am

Generated in about 0.249s.

(Used 8 db queries)

mobile phone