Net::DNS-> About setting more than one nameserver to lookup.

Discussion in 'Perl Misc' started by eloelo, Aug 7, 2004.

  1. eloelo

    eloelo Guest

    I want to use four nameserver to look up a domain's IP.
    But why the code below can lookup domain's IP only using one nameserver.


    #!/usr/bin/perl
    use Net::DNS;
    @ns=('222.33.11.2','223.55.4.3','223.55.4.2','223.55.4.7');

    for($i=0;$i<4;$i++)
    {
    my $res = Net::DNS::Resolver->new;
    $res->nameservers($ns);
    my $query = $res->search("www.bdchina.com");

    if ($query)
    {
    foreach my $rr ($query->answer)
    {
    next unless $rr->type eq "A";
    print "$ns---->",$rr->address, "\n";
    }
    }
    else
    {
    warn "$ns---->query failed: ", $res->errorstring, "\n";
    }
    }
     
    eloelo, Aug 7, 2004
    #1
    1. Advertising

  2. eloelo

    Michael Fuhr Guest

    eloelo <> writes:

    > I want to use four nameserver to look up a domain's IP.
    > But why the code below can lookup domain's IP only using one nameserver.


    Add "use warnings" to your script and let Perl tell you. Many
    programmers consider "use strict" to be good practice as well.

    > #!/usr/bin/perl
    > use Net::DNS;
    > @ns=('222.33.11.2','223.55.4.3','223.55.4.2','223.55.4.7');
    >
    > for($i=0;$i<4;$i++)
    > {
    > my $res = Net::DNS::Resolver->new;
    > $res->nameservers($ns);
    > my $query = $res->search("www.bdchina.com");
    >
    > if ($query)
    > {
    > foreach my $rr ($query->answer)
    > {
    > next unless $rr->type eq "A";
    > print "$ns---->",$rr->address, "\n";
    > }
    > }
    > else
    > {
    > warn "$ns---->query failed: ", $res->errorstring, "\n";
    > }
    > }


    --
    Michael Fuhr
    http://www.fuhr.org/~mfuhr/
     
    Michael Fuhr, Aug 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thilo Rusche

    host lookup on specific nameserver

    Thilo Rusche, Jul 28, 2003, in forum: Java
    Replies:
    3
    Views:
    642
    Thilo Rusche
    Jul 29, 2003
  2. Merciadri Luca
    Replies:
    4
    Views:
    835
  3. Sam Roberts
    Replies:
    0
    Views:
    227
    Sam Roberts
    Mar 20, 2005
  4. Steven D'Aprano
    Replies:
    0
    Views:
    116
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    98
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page