Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:02:02+00:00 2026-05-29T23:02:02+00:00

So, in the otter book , there is a small script(see page 173) whose

  • 0

So, in the otter book, there is a small script(see page 173) whose purpose is to iteratively check DNS servers to see if they are returning the same address for a given hostname. However, the solution given in the book works only when the host has a static IP address. How would I write this script if I wanted it to work with hosts that have multiple addresses associated with them?

Here is the code:

#!/usr/bin/perl
use Data::Dumper;
use Net::DNS;

my $hostname = $ARGV[0];
# servers to check
my @servers = qw(8.8.8.8 208.67.220.220 8.8.4.4);

my %results;
foreach my $server (@servers) {
    $results{$server} 
        = lookup( $hostname, $server );
}

my %inv = reverse %results; # invert results - it should have one key if all
                           # are the same
if (scalar keys %inv > 1) { # if it has more than one key
    print "The results are different:\n";
    print Data::Dumper->Dump( [ \%results ], ['results'] ), "\n";
}

sub lookup {
    my ( $hostname, $server ) = @_;

    my $res = new Net::DNS::Resolver;
    $res->nameservers($server);
    my $packet = $res->query($hostname);

    if ( !$packet ) {
        warn "$server not returning any data for $hostname!\n";
        return;
    }
    my (@results);
    foreach my $rr ( $packet->answer ) {
        push ( @results, $rr->address );
    }
    return join( ', ', sort @results );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:02:03+00:00Added an answer on May 29, 2026 at 11:02 pm

    The problem I had was that I was getting this error calling the code on a hostname that returned multiple addresses, such as http://www.google.com:

    ***  WARNING!!!  The program has attempted to call the method
    ***  "address" for the following RR object:
    ***
    ***  www.google.com.    86399   IN  CNAME   www.l.google.com.
    ***
    ***  This object does not have a method "address".  THIS IS A BUG
    ***  IN THE CALLING SOFTWARE, which has incorrectly assumed that
    ***  the object would be of a particular type.  The calling
    ***  software should check the type of each RR object before
    ***  calling any of its methods.
    ***
    ***  Net::DNS has returned undef to the caller.
    

    This error meant that I was trying to call the address method on an rr object of type CNAME. I want to call the address method only on rr objects of type ‘A’. In the code above, I have no checks to make sure I’m calling address on objects of type ‘A’. I added this line of code(the next unless one), and it works:

    my (@results);
    foreach my $rr ( $packet->answer ) {
        next unless $rr->type eq "A";
        push ( @results, $rr->address );
    }
    

    This line of code skips to the next address gotten from $packet->answer unless the rr object’s type is “A”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On page 13 in the GoF book there is a statement: Two objects of
Is there an online Java book like Dive into Python for learning Python? Other
There is a small part of our software that inserts a string before and
Is there some sort of Learning C for developers of other languages book or
Is there a simple way to do the Curl page flipping animation? A Curl
I am reading Scott Meyers Effective C++ book. It was mentioned that there are
Is there a nice e-book (preferably PDF, like Array and Pointers in C )
There is a picture of a DAG in the book 'Building and Testing with
Is there any documentation about internal structure of Git index file? From various book
In Java Concurrency In Practice book (p.156), there's a statement regarding poison pill approach:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.