View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Dianne Skoll > Net-DNSBL-Client-0.206 > Net::DNSBL::Client



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 0.206   Source  


Net::DNSBL::Client - Client code for querying multiple DNSBLs


    use Net::DNSBL::Client;
    my $c = Net::DNSBL::Client->new({ timeout => 3 });

    $c->query_ip('', [
            { domain => 'simple.dnsbl.tld' },
            { domain => 'masked.dnsbl.tld', type => 'mask', data => '' },
            { domain => 'txt.dnsbl.tld', type => 'txt' },
            { domain => '' }],
        { lookup_keys => { '' => 'my_secret_key' }});

    # And later...
    my $answers = $c->get_answers();


Class Methods

new ( $args )

Returns a new Net::DNSBL::Client object.

$args is a hash reference and may contain the following key-value pairs:


(optional) A Net::DNS::Resolver object. If not provided, a new resolver will be created.


(optional) An integer number of seconds to use as the upper time limit for the query. If not provided, the default is 10 seconds. If provided, timeout must be a positive integer.

Instance Methods

get_resolver ( )

Returns the Net::DNS::Resolver object used for DNS queries.

get_timeout ( )

Returns the timeout in seconds for queries.

set_timeout ( $secs )

Sets the timeout in seconds for queries.

query_is_in_flight ( )

Returns non-zero if "query" has been called, but "get_answers" has not yet been called. Returns zero otherwise.

query_ip ( $ipaddr, $dnsbls [, $options])

Issues a set of DNS queries. Note that the query_ip() method returns as soon as the DNS queries have been issued. It does not wait for DNS responses to come in. Once query_ip() has been called, the Net::DNSBL::Client object is said to have a query in flight. query_ip() may not be called again while a query is in flight.

$ipaddr is the text representation of an IPv4 or IPv6 address.

$dnsbls is a reference to a list of DNSBL entries; each DNSBL entry is a hash with the following members:


(required) The domain to query. For example,


(optional) The type of DNSBL. Possible values are normal, meaning that any returned A record indicates a hit, match, meaning that one of the returned A records must exactly match a given IP address, mask, meaning that one of the returned A records must evaluate to non-zero when bitwise-ANDed against a given IP address, or txt meaning that TXT records should be looked up and returned (rather than A records)a. If omitted, type defaults to normal


(optional) For the match and mask types, this data specifies the required match or the bitwise-AND mask. In the case of a mask type, the data can be something like "", or an integer like "8". In the latter case, the integer n must range from 1 to 255 and is equivalent to 0.0.0.n.


(optional) This element can be any scalar or reference that you like. It is simply returned back unchanged in the list of hits.

$options, if supplied, is a hash of options. Currently, three options are defined:


If set to 1, querying will stop after the first positive result is received, even if other DNSBLs are being queried. Default is 0.


If set to 1, then the return value from get_answers() will contain all DNSBLs that were supplied to query_ip(), even if the DNSBL did not hit. If set to 0 (the default), then the return value from get_answers() only returns entries for those DNSBLs that actually hit.


This is a hashref of domain_name => key. Some domains require a secret key to be inserted just before the domain name; rather than including the key in the domain, you can separate it out with the lookup_keys hash, making the returned results more readable.

query_domain ( $domain, $dnsbls [, $options])

Similar to query_ip, but considers $domain to be a domain name rather than an IP address, and does not reverse the domain.

get_answers ( )

This method may only be called while a query is in flight. It waits for DNS replies to come back and returns a reference to a list of hits. Once get_answers() returns, a query is no longer in flight.

Note that the list of hits is not necessarily returned in the same order as the original list of DNSBLs supplied to query_ip().

Each hit in the returned list is a hash reference containing the following elements:


The domain of the DNSBL.


Set to 1 if the DNSBL was hit or 0 if it was not. (You will only get entries with hit set to 0 if you used the return_all option to query_ip().)


The type of the DNSBL (normal, match or mask).


The data supplied (for normal and mask types)


The userdata as supplied in the query_ip() call


Reference to array containing actual A or TXT records returned by the lookup that caused a hit.


The reply code from the DNS server (as a string). Likely to be one of NOERROR, NXDOMAIN, SERVFAIL or TIMEOUT. (TIMEOUT is not a real DNS reply code; it is synthesized by this Perl module if the lookup times out.)

The hit may contain other elements not documented here; you should count on only the elements documented above.

If no DNSBLs were hit, then a reference to a zero-element list is returned.


Net::DNS::Resolver, IO::Select


Dianne Skoll <>, Dave O'Neill <>


Copyright (c) 2010 Roaring Penguin Software

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: