I am trying to achieve lookups for each IP in each nameserver, telling me success or no success.

We can disregard your first three bullet points, but the fourth yes I should only need to create one object. But since I have two nameservers, I need to lookup all these IPs twice, once in each nameserver. So do I still need one object? If so how do I dereference it? This code right below works, but no sure how to implement in the $res object code?

#for my $ns (@namesvr) { # for my $keys (sort keys %$ns) { # print "$keys => $ns->{$keys}\n"; # } # print "\n"; #} #exit;

#!/usr/bin/perl use strict; use warnings; use Carp; use Net::DNS; use Data::Dumper; ## AoH my @namesvr = ( { NAME => 'ns#.xxxx.com', IPLIST => [] } , +## Autovivification { NAME => 'wrnaxxxx.xx.xxxxx.com', IPLIST => [] } ) ; #print Dumper(\@namesvr);exit; my %IPinfo; ## HoH for my $IP (qw ( 10.220.84.30 10.220.84.51 10.220.84.52 10.220.84.54 10.220.84.55 10.220.84.56 10.220.84.57 10.220.84.58 )) { $IPinfo{$IP} = {DOMAININDEX => undef, TYPE => "CLIEN +T" } ; } our ( $res, $IP ) ; for my $ns (@namesvr) { for my $keys (sort keys %$ns) { $res = Net::DNS::Resolver->new ( nameservers => [$ns->{$keys}], recurse => 1, ## do recursive lookups retry => 1, debug => 0, ); } } for my $ip (keys %IPinfo) { for my $ids (0..$#namesvr) { my $ptr = nsqry($namesvr[$ids]->{NAME}, $ip) ; # nsqry has bee +n modified to return the info next unless $ptr ; # No change, if $ptr is empty $IPinfo{$ip}{DOMAININDEX} = $ids ; # Forward ref from IP to DO +MAIN $IPinfo{$ip}{PTR} = $ptr ; push @{$namesvr[$ids]->{IPLIST}}, $ip ; # Keep a list of IP's +that live in this domain } } sub nsqry { ( $res, $IP ) = @_ ; my $query = $res->query($IP, 'PTR') ; if ($query) { for my $rr ($query->answer) { next unless ($rr->type eq 'PTR') ; ## skip record if not e +q PTR ## print $rr->ptrdname ; return $rr->ptrdname ; } return undef ; } else { carp "query failed for $IP: ", $res->errorstring, "\n" ; return undef ; } }

In reply to Re^4: loop ending b4 I want it to by mikejones
in thread loop ending b4 I want it to by mikejones

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.