Lookuping IP address using four nameservers at the same time.

F

Facco Eloelo

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.
 
T

Tom Regner

Facco said:
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
 
G

Gregory Toomey

Facco said:
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
 
G

Gregory Toomey

Tom said:
Facco Eloelo wrote:
.....
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
 
T

Tom Regner

Gregory said:
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
#
 
B

Brian McCauley

Facco said:
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::DNS 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.
 
T

Tom Regner

Facco said:
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::Dumper;
print Data::Dumper->Dump([$results,],["result"]);
#
# do something with results
#
 
D

David K. Wall

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. :)
 
T

Tom Regner

David said:
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
 
G

Gregory Toomey

Tom said:
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
 
P

Patrice Auffret

On Thu, 05 Aug 2004 14:40:23 +0200
Tom Regner said:
for (@children) {waitpid($_, 0);}
[..]


You can put a signal handler in parent process to avoid waitpid()
(since returned status is ignored).

$SIG{CHLD} = 'IGNORE';
 
B

Ben Morrow

Quoth Patrice Auffret said:
On Thu, 05 Aug 2004 14:40:23 +0200
Tom Regner said:
for (@children) {waitpid($_, 0);}
[..]


You can put a signal handler in parent process to avoid waitpid()
(since returned status is ignored).

$SIG{CHLD} = 'IGNORE';

This isn't strictly portable: perlipc says that 'most Unix platforms'
have this behaviour, but it isn't guaranteed (it depends on your
kernel/C library).

Ben
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top