in reply to Re: Net::DNS::Resolver and very slow reply
in thread Net::DNS::Resolver and very slow reply

Yes, i'm pretty sure there's nothing wrong with it. When using Nslookup from Command Prompt (i'm on windows) and querying against our own domain, it takes about 0.05 seconds to answer back. When querying the same domain with this script, it takes that five to six seconds.

I have the same problem from home as well, with totally different network and using my ISP's DNS server. I've even tested this script on Windows XP and OS X, so i'm really confused here if you get it to answer in a fractions of a second.

  • Comment on Re^2: Net::DNS::Resolver and very slow reply

Replies are listed 'Best First'.
Re^3: Net::DNS::Resolver and very slow reply
by McDarren (Abbot) on Sep 04, 2006 at 14:18 UTC
    mmm, okay.
    Well, just for the sake of the exercise, I re-wrote your script and simplified it a bit. I also changed it so that it would take a domain name to test from the command line. Here is my version:
    #!/usr/bin/perl -w use strict; use Net::DNS; my $domain = shift or die "Please supply a domain to query\n"; my @ips = resolve($domain); my $i; for (@ips) { print ++$i . ": $_\n"; } sub resolve { my $domain = shift; my $res = Net::DNS::Resolver->new; my $query = $res->search($domain); my @results; if ($query) { foreach my $rr ($query->answer) { next if $rr->type ne "A"; push @results, $rr->address . " (record type " . $rr->type + . ")"; } return @results; } else { return $res->errorstring; } }

    I get similar results with this as I did with your original, but perhaps you can try this and see if it makes any difference. Some sample output:

    time perl resolver.pl cnn.com 1: 64.236.24.12 (record type A) 2: 64.236.24.20 (record type A) 3: 64.236.24.28 (record type A) 4: 64.236.29.120 (record type A) 5: 64.236.16.20 (record type A) 6: 64.236.16.52 (record type A) 7: 64.236.16.84 (record type A) 8: 64.236.16.116 (record type A) real 0m0.562s user 0m0.320s sys 0m0.010s

    As you can see, still quite fast. I also tried it on a windoze box and it returns just as quickly.

    Hope this helps somewhat,
    Darren :)

      McDarren, rewritten by you it works very quickly now! Like really_quickly. Thank you very much :)

      I Think i have to examine my version a little more closer once i get back to home, since there must be something very much wrong with it. How else could there be this much of a speed difference.

      Once again, thank you for rewriting this. Now i can move on with the actual program ;)

Re^3: Net::DNS::Resolver and very slow reply
by mda2 (Hermit) on Sep 04, 2006 at 14:38 UTC
    Using an Windows XP on dial connection made this times:
    C:\Documents and Settings\mda>perl dns.pl 11 wallclock secs ( 0.00 usr + 0.03 sys = 0.03 CPU)1: 200.228.126.26 + (record type A)
    The changes has:
    use Benchmark; my $td = new Benchmark; my @domainIp = resolveDomainIp ('hostname'); print timestr(timediff(new Benchmark, $td));

    But a question... Why nslookup is more quickly?
    I donīt known details, but supose the use of caches on windows, or more simple do identify nameserver...

    When I defining my nameserver has a less time. Checking why, I see other nameserver (local connection... lost configs ?)...

    #.. cut .. my $res = Net::DNS::Resolver->new; print "PRE: ", $res->nameservers, "\n"; $res->nameservers('my.desired.ip.addr'); print "POS: ", $res->nameservers, "\n"; #.. cut ..
    Note:

    --
    Marco Antonio
    Rio-PM