Robert Arnold wrote:
> 
> (resending since first try through smtp.comcast.net was /dev/nulled
> somewhere...)
> 
> I'm having some trouble finding a way to query a specific dns server
> for the text record of a given name purely in perl. I'm trying to do
> this with Net::DNS, but it's proving difficult as I'm not very
> experienced with objects.
> 
> I'm running rbldnsd (a daemon for running dnsbls:
> http://www.corpit.ru/mjt/rbldnsd.html)  on a box on my local NAT
> network. If the hostname queried for is listed (in whatever zone I'm
> using, be it DSBL, SBL,etc or one of my own), rbldnsd returns
> '127.0.0.2'. If that is returned, I want to fetch the text (TXT)
> record for the hostname as well, which includes further information
> about the listing.
> 
> The code which finds the 'A' record below is pretty much straight from
> the example the author of Net::DNS included:
> 
> ###/snip
> 
> use Net::DNS;
> $IP=shift;
> ($a,$b,$c,$d) = split (/\./,$IP);
> $host="$d\.$c\.$b\.$a\.rbl\.foo\.com";
> my $res  = Net::DNS::Resolver->new;
> $res->nameservers("192.168.0.72");
> my $query=$res->search("$host");
> if ($query) {
>       foreach my $rr ($query->answer) {
>           next unless $rr->type eq "A";
>           $addy=$rr->address;
>       }
>         if ($addy=~/127\.0\.0\.2/) {
>         #how the fsck do you find txt records with Net::DNS???
>         $txt=`host -t txt $host 192.168.0.72|sed -e 's/\"//g' -ne '6p'|awk \'\{print 
> \$3\}\'`;
>         print "$IP -> $txt";
>         }
> } else {
>       print "NULL\n";
>   }

This should work (not tested with rbldnsd.)

#!/usr/bin/perl
use warnings;
use strict;

use Net::DNS;

my $IP = shift;
my ( $a, $b, $c, $d ) = split /\./, $IP;
my $host = "$d.$c.$b.$a.rbl.foo.com";

my $res  = Net::DNS::Resolver->new;
$res->nameservers( '192.168.0.72' );

# Important to specify a 'TXT' query
my $query = $res->search( $host, 'TXT' ) or die "NULL\n";

foreach my $rr ( $query->answer ) {
    next unless $rr->type eq 'TXT';
    print $rr->txtdata, "\n";
    }

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to