#!/usr/bin/perl # This program is used by the web server to look up whether or not IP # addresses are block. # Note that we need to reopen the cdb database for each lookup or else # we will be seeing old data. # The CDB file is in rbldns format. use CDB_File; $| = 1; chdir '/var/www/html/robot'; while () { chop; $addr = $_; $ip = 0; if (m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) { $ip = pack 'CCCC', $1, $2, $3, $4; } else { print "BLOCKED\n"; next; } $ip = unpack 'N', $ip; tie %ip, 'CDB_File', 'ip/data.cdb'; for ($i=0; $i<=24; $i++) { $ip >>= $i; $ip <<= $i; $key = pack 'NC', $ip, 32 - $i; next unless defined $ip{$key}; print "BLOCKED\n"; last; } untie %ip; print "OK\n" if $i > 24; }