Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Lookuping IP address using four nameservers at the same time.

Reply
Thread Tools

Lookuping IP address using four nameservers at the same time.

 
 
Facco Eloelo
Guest
Posts: n/a
 
      08-05-2004
I have 4 DNS servers
e.g.
111.111.111.111;
222.222.222.222;
111.222.111.222;
222.111.222.111.
They are fake here for secure reason

When I want to get a domain's IP,I usually type:

"nslookup"-->"server 111.111.111.111"-->"www.aaa.com"
then "server 222.222.222.222"-->"www.aaa.com"
and then "server 111.222.111.222"-->"www.aaa.com"
and then "server 222.111.222.111"-->"www.aaa.com"

But I find it costs lots of my time.

Is there a tool (or just a perl script) which can set four nameservers(or more)
*at the same time* to query?

Thank you in advance.
 
Reply With Quote
 
 
 
 
Tom Regner
Guest
Posts: n/a
 
      08-05-2004
Facco Eloelo wrote:

> I have 4 DNS servers
> e.g.
> 111.111.111.111;
> 222.222.222.222;
> 111.222.111.222;
> 222.111.222.111.
> They are fake here for secure reason
>
> When I want to get a domain's IP,I usually type:
>
> "nslookup"-->"server 111.111.111.111"-->"www.aaa.com"
> then "server 222.222.222.222"-->"www.aaa.com"
> and then "server 111.222.111.222"-->"www.aaa.com"
> and then "server 222.111.222.111"-->"www.aaa.com"
>
> But I find it costs lots of my time.
>
> Is there a tool (or just a perl script) which can set four nameservers(or
> more) *at the same time* to query?
>
> Thank you in advance.


Short of using Net-DNS (http://search.cpan.org/~crein/Net-DNS-0.47_01/)
if it's just a little helper, why not use something like this:

#!/bin/env perl
use warnings;
use strict;
my @dnss = qw(111.111.111.111
222.222.222.222
111.222.111.222
222.111.222.111);

my $host = $_[0];

foreach (@dnss) {
my $res = qx/nslookup -type=A $host $_/;
(print $res and exit(0)) if $res;
}

called as './script.pl searchterm'
(untested)
hth,
Tom
--
Dievision GmbH | Kriegerstrasse 44 | 30161 Hannover
Telefon: (0511) 288791-0 | Telefax: (0511) 288791-99
http://www.dievision.de
 
Reply With Quote
 
 
 
 
Gregory Toomey
Guest
Posts: n/a
 
      08-05-2004
Facco Eloelo wrote:

> I have 4 DNS servers
> e.g.
> 111.111.111.111;
> 222.222.222.222;
> 111.222.111.222;
> 222.111.222.111.
> They are fake here for secure reason
>
> When I want to get a domain's IP,I usually type:
>
> "nslookup"-->"server 111.111.111.111"-->"www.aaa.com"
> then "server 222.222.222.222"-->"www.aaa.com"
> and then "server 111.222.111.222"-->"www.aaa.com"
> and then "server 222.111.222.111"-->"www.aaa.com"
>
> But I find it costs lots of my time.
>
> Is there a tool (or just a perl script) which can set four nameservers(or
> more) *at the same time* to query?
>
> Thank you in advance.


I'm trying to do something similar - given a domain, try to do dig, whois &
ping in parallel.

The first attempt was a non-blocking pipe open. But to do it for multiple
files it needs co-routines which are not simple to implement:
http://tinyurl.com/5jwwg

Another approach I'm considering is
1. Start a number of processes in the background, writing to temp files:
system("command1 arg1 &>/tmp/file1");
system("command2 argt2 &>/tmp/file2");
system("command3 argt3 &>/tmp/file3");

2. Read each of /tmp/file* by polling them in a loop and sleeping for say 1
sec .
3. Parse the files

Either approach is not pretty.

gtoomey
 
Reply With Quote
 
Gregory Toomey
Guest
Posts: n/a
 
      08-05-2004
Tom Regner wrote:

> Facco Eloelo wrote:
>


>> Is there a tool (or just a perl script) which can set four nameservers(or
>> more) *at the same time* to query?
>>

.....
> foreach (@dnss) {
> my $res = qx/nslookup -type=A $host $_/;
> (print $res and exit(0)) if $res;
> }
>


The OP wants the results in parallel. This does it sequentially.

gtoomey
 
Reply With Quote
 
Tom Regner
Guest
Posts: n/a
 
      08-05-2004
Gregory Toomey wrote:

> Tom Regner wrote:
>
>> Facco Eloelo wrote:
>>

>
>>> Is there a tool (or just a perl script) which can set four
>>> nameservers(or more) *at the same time* to query?
>>>

> ....
>> foreach (@dnss) {
>> my $res = qx/nslookup -type=A $host $_/;
>> (print $res and exit(0)) if $res;
>> }
>>

>
> The OP wants the results in parallel.

Ah, I overread this part, silly me...
I understood the OP as just to want to avoid the typing...

> This does it sequentially

I know

Than I modify my approach slightly: untested (especialy the use of $_ in the
child-processes seems to be suspicious), but maybe a start; Access to
$store->$result should be governed by a lock or something, but that s to
much to look into right now.

hth,
Tom

------------------------------------------------------

#!/bin/env perl
use warnings;
use strict;
use IPC::ShareLite;
use Storable qw(thaw freeze);
my $store = new IPC::ShareLite( -key => "__dnssearch__",
-create => 'yes',
-destroy => 'no' ) or die $!;

my $results = {};

$store->store(freeze($results));

my @dnss = qw(111.111.111.111
222.222.222.222
111.222.111.222
222.111.222.111);

my $host = $_[0];
my @children = ();
foreach (@dnss) {
my $parent = fork();
if (!$parent) {
my $res = qx/nslookup -type=A $host $_/;
my $store = new IPC::ShareLite( -key => "__dnssearch__",
-create => 'yes',
-destroy => 'no' ) or warn ("Child $_:
". $!);
#
# needs some kind of locking?!?
#
my $results = thaw($store->fetch());
$results->{$_} = $res;
$store->store(freeze($results));
} else {
die "couldn't fork!" unless $parent;
push(@children, $parent);
}
}
while ($#children) {
my $child = wait();
pop @children;
}

$results = thaw($store->fetch());
#
# do something with results
#

------------------------------------------------------

--
Dievision GmbH | Kriegerstrasse 44 | 30161 Hannover
Telefon: (0511) 288791-0 | Telefax: (0511) 288791-99
http://www.dievision.de
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      08-05-2004

Facco Eloelo wrote:
>
> Is there a tool (or just a perl script) which can set four nameservers(or more)
> *at the same time* to query?


In the Net:NS examples there is a script that looks up several names
on one server at once. It would not be too hard to make it look up one
address on several servers at once.

http://search.cpan.org/~crein/Net-DNS/demo/mresolv

However I would query why you think that you want to do this. Are you
debugging DNS propagation? In the normal course of events you'd just
ask you local recursive nameserver and let it do all the work.

 
Reply With Quote
 
Tom Regner
Guest
Posts: n/a
 
      08-05-2004
Facco Eloelo wrote:

> I have 4 DNS servers
> e.g.
> 111.111.111.111;
> 222.222.222.222;
> 111.222.111.222;
> 222.111.222.111.
> They are fake here for secure reason
>
> When I want to get a domain's IP,I usually type:
>
> "nslookup"-->"server 111.111.111.111"-->"www.aaa.com"
> then "server 222.222.222.222"-->"www.aaa.com"
> and then "server 111.222.111.222"-->"www.aaa.com"
> and then "server 222.111.222.111"-->"www.aaa.com"
>
> But I find it costs lots of my time.
>
> Is there a tool (or just a perl script) which can set four nameservers(or
> more) *at the same time* to query?
>
> Thank you in advance.


working version of my previously posted code, still just a draft, but tested
(with real servers) and working:

#!/bin/env perl
use warnings;
use strict;
use IPC::ShareLite;
use Storable qw(thaw freeze);
use File::Temp qw(tempfile);
use Fcntl ':flock';
use POSIX ":sys_wait_h";

my $store = new IPC::ShareLite( -key => "__dnssearch__",
-create => 'yes',
-destroy => 'no' ) or die "Store: " .
$!;

my $results = {};

$store->store(freeze($results));

my @dnss = qw(111.111.111.111
222.222.222.222
111.222.111.222
222.111.222.111);

my $host = $ARGV[0];
my @children = ();
my $lock = tempfile();

foreach (@dnss) {
my $dns = $_;
my $parent = fork();
if (!$parent) {
my $command = "nslookup -type=A $host $dns 2>/dev/null";
my $res = qx/$command/;
my $store = new IPC::ShareLite( -key => "__dnssearch__",
-create => 'yes',
-destroy => 'no' ) or warn ("Child $_:
". $!);
flock($lock, LOCK_EX);
my $results = thaw($store->fetch());
$results->{$dns} = $res;
$store->store(freeze($results));
flock($lock, LOCK_UN);
exit(0);
} else {
die "couldn't fork!" unless $parent;
push(@children, $parent);
}
}
for (@children) {waitpid($_, 0);}

$results = thaw($store->fetch());
use Data:umper;
print Data:umper->Dump([$results,],["result"]);
#
# do something with results
#

--
Dievision GmbH | Kriegerstrasse 44 | 30161 Hannover
Telefon: (0511) 288791-0 | Telefax: (0511) 288791-99
http://www.dievision.de
 
Reply With Quote
 
David K. Wall
Guest
Posts: n/a
 
      08-05-2004
Gregory Toomey <> wrote in message
<news:>:

> Tom Regner wrote:
>
>> Facco Eloelo wrote:
>>

>
>>> Is there a tool (or just a perl script) which can set four
>>> nameservers(or more) *at the same time* to query?
>>>

> ....
>> foreach (@dnss) {
>> my $res = qx/nslookup -type=A $host $_/;
>> (print $res and exit(0)) if $res;
>> }
>>

>
> The OP wants the results in parallel. This does it sequentially.


OK, this has little to do with Perl, but can someone explain to me why
this makes a difference? Yes, I'm ignorant; that's why I asked.

 
Reply With Quote
 
Tom Regner
Guest
Posts: n/a
 
      08-05-2004
David K. Wall wrote:
> Gregory Toomey <> wrote in message
> <news:>:
>
>> Tom Regner wrote:
>>
>>> Facco Eloelo wrote:
>>>

>>
>>>> Is there a tool (or just a perl script) which can set four
>>>> nameservers(or more) *at the same time* to query?
>>>>

>> ....
>>> foreach (@dnss) {
>>> my $res = qx/nslookup -type=A $host $_/;
>>> (print $res and exit(0)) if $res;
>>> }
>>>

>>
>> The OP wants the results in parallel. This does it sequentially.

>
> OK, this has little to do with Perl, but can someone explain to me why
> this makes a difference? Yes, I'm ignorant; that's why I asked.


I guess because most of the time is spent waiting, that means
sequentiell:

time = sum(each process);

parallel:
time = max(time(processes));

so despite the overhead in organizing parallel execution, you might save a
lot of time.

kind regards
Tom
--
Dievision GmbH | Kriegerstrasse 44 | 30161 Hannover
Telefon: (0511) 288791-0 | Telefax: (0511) 288791-99
http://www.dievision.de
 
Reply With Quote
 
Gregory Toomey
Guest
Posts: n/a
 
      08-05-2004
Tom Regner wrote:

> David K. Wall wrote:
>> Gregory Toomey <> wrote in message
>> <news:>:
>>
>>> Tom Regner wrote:
>>>
>>>> Facco Eloelo wrote:
>>>>
>>>
>>>>> Is there a tool (or just a perl script) which can set four
>>>>> nameservers(or more) *at the same time* to query?
>>>>>
>>> ....
>>>> foreach (@dnss) {
>>>> my $res = qx/nslookup -type=A $host $_/;
>>>> (print $res and exit(0)) if $res;
>>>> }
>>>>
>>>
>>> The OP wants the results in parallel. This does it sequentially.

>>
>> OK, this has little to do with Perl, but can someone explain to me why
>> this makes a difference? Yes, I'm ignorant; that's why I asked.

>
> I guess because most of the time is spent waiting, that means
> sequentiell:
>
> time = sum(each process);
>
> parallel:
> time = max(time(processes));
>
> so despite the overhead in organizing parallel execution, you might save a
> lot of time.
>
> kind regards
> Tom


The other issue is that one of the programs may "hang" and not return
anything. This is especially try if you are working with DNS & trying to
diagnose problems.

gtoomey
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Canon EIS mirrorless system - Four Thirds, but not Four Thirds! Bruce Digital Photography 31 09-25-2010 05:38 AM
IPSTAG and nameservers t Computer Support 17 02-21-2008 07:14 PM
Find out the NameServers of a Domain name Vinay Beckham Ruby 2 08-29-2007 08:24 PM
Does gmail bounce emails from certain nameservers? benzden Computer Support 9 12-16-2006 08:22 PM
How to use perl to get all of a domains' nameservers. Facco Eloelo Perl Misc 2 08-02-2004 11:33 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57