g_speran has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl monks, Just to start off with, I am not a DNS expert by no means so I am going to try to ask with what I have In our DNS server, we have a forward zone called "mycompany.local". in here we have an entry 192.168.100.100 to t4400-100 Two reverse zone 100.168.192 and 110.168.192. In both of these reverse zones, there is an entry for t4400-100

100.168.192 - has t4400-100 associated with 192.168.100.100
110.168.192 - has t4400-100 associated with 192.168.110.100
Is there a way/process, when looking up the host name of t4400-100, it will return both IP address of 192.168.100.100 & 192.168.110.100

#!/usr/bin/perl -w # hostaddrs - canonize name and show addresses use Socket; use Net::hostent; use strict; print "\nHost_Name \n"; my ($name, $hent, @addresses); $name = shift || die "usage: $0 hostname\n"; if ($hent = gethostbyname($name)) { $name = $hent->name; # in case different my $addr_ref = $hent->addr_list; @addresses = map { inet_ntoa($_) } @$addr_ref; } print "$name => @addresses\n";
Output I:\>perl dnslookup.pl t4400-202.mycompany.local Host_Name t4400-202.mycompany.local => 192.168.100.202 ( ==> wanting to show 192.168.110.202 as well <== I:\>

Discipulus changed some formatting

Replies are listed 'Best First'.
Re: DNS lookup
by hippo (Archbishop) on Feb 14, 2023 at 16:56 UTC

    I tend to avoid gethostbyname and similar these days and instead turn to Net::DNS for all my DNS needs. Using this we can do:

    #!/usr/bin/env perl use strict; use warnings; use Net::DNS; my @rr = rr ('www.perlmonks.org', 'A'); for my $rec (@rr) { next unless $rec->type eq 'A'; print "Found: " . $rec->rdstring . "\n"; }

    🦛

      this code still only found the 192.168.100.x and not the 192.168.110.x address

        Well, if your hostname is only set up to resolve to a single IP address in your DNS then that's fine. If you want it to resolve to multiple addresses you will need to talk to your DNS maintainer and have them modify the zone so that it does (as happens with www.perlmonks.org).


        🦛

        Maybe it's a round robin setup (multiple addresses for a name, only one gets send to the client at any given time)

        Lookup type ANY should give more informations, but that also depends on the server configuration.

        PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
Re: DNS lookup
by alexander_lunev (Pilgrim) on Feb 15, 2023 at 06:56 UTC

    Hello!

    No, you can't search reverse zone by returning value. As in a Perl hash, you can't have exists $hash->{$value}, but only exists $hash->{$key}. Search for an IP address 192.168.110.202 in reverse zone is a simple search for value of 202.110.168.192.in-addr.arpa and nothing more, and if I remember correctly, you can't enter two values for IN PTR, as this entry must return one unique value.

    You need to add to your forward zone two entries for one name, like this (pardon me if this example will not work in your DNS server, i write it from memory):

    @ORIGIN mycompany.local t4400-202 IN A 192.168.100.202 IN A 192.168.110.202

    Then you can get two addresses for one search query for t4400-202.mycompany.local.

Re: DNS lookup
by Anonymous Monk on Feb 14, 2023 at 17:45 UTC
    sounds like a DNS question, not a Perl question. what does dig say?
      No Linux UX* in the environment. only windows