[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] RBL with Perl



This came up in a local newsgroup:

In article <sfrtosheeoc108@corp.supernews.com>,
        cmadams@HiWAAY.net (Chris Adams) writes:

: I guess you could write a function to do that:
: 
: sub on_rbl
: {
:       my $addr = shift || return 0;
:       $addr = join (".", reverse (split (/\./, $addr)));
:       return 1 if (gethostbyname ($addr . ".rbl.maps.vix.com"));
:       return 0;
: }
: 
: but you'd end up with more overhead for Exporter, etc. than code for the
: module, and it would be kind of boring. :-)

We don't need no steenking Exporter!

    package RBL;

    use strict;

    sub import {
        no strict 'refs';

        my($pkg) = caller;

        *{ $pkg . '::' . 'on_rbl' } = \&on_rbl;
        *{ $pkg . '::' . 'TARGET' } = \&TARGET;
    }

    # the RBL target: inet_aton '2.0.0.127'
    sub TARGET () { "\cB\c@\c@\c?" }

    sub on_rbl {
        return unless @_;

        my $result = gethostbyname join ".", reverse split /\./, shift;

        ($result || '') eq TARGET;
    }

    1;

Use it like

    #! /usr/bin/perl -w

    use strict;

    use RBL;

    my $addr = shift || "127.0.0.2";

    print "`$addr' " . ( on_rbl($addr) ? "is" : "is not" ) . " on RBL\n";

Cool!

Greg
-- 
Laws do not persuade just because they threaten.
    -- Seneca

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe