Chris wrote:
> I'm attempting to convert an ip address (80.224.159.46) info a fully
> qualified domain (46.159.244.80.sbl-xbl.spamhaus.org) and then make a dns
> query to determine if any records exist. I cant seem to figure our what I'm
> doing wrong here.
>
>
> use strict;
> use Net::DNS;
>
> my($the_ip,$the_domain,$rr,$the_query);
>
> $the_ip='80.224.159.46';
>
> $the_ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
> $the_domain="$4.$3.$2.$1.sbl-xbl.spamhaus.org";
You can get the FQDN from IP using:
my $ip = shift || '80.224.159.46';
my $FQDN = gethostbyaddr (inet_aton ($ip), AF_INET) or
die "Error on gethostbyaddr: $_ ($^E)";
print "ip=$ip, FQDN=$FQDN\n";
> my $res = Net::DNS::Resolver->new(
> recurse => 1,
> debug => 0,
> );
>
> $the_query = $res->search($the_domain);
>
> foreach $rr ($the_query->answer) {
> print $rr->address."\n";
> }
my $res = Net::DNS::Resolver->new(recurse => 1, debug => 0);
# search and query bot seem to work using IP rather than FQDN which
# fails for me
# my $query = $res->search($ip) or die "search($ip): $! ($^E)";
my $query = $res->query($ip) or die "query($ip): $! ($^E)";
# not sure what the proper retrieval method is, but this works:
foreach my $rr (@{$query->{answer}}) {
foreach (keys %{$rr}) {
print "$_ => $rr->{$_}\n";
}
}
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs