CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
how can we update the nameserver when the script is running

 



boliu83
New User

May 4, 2009, 5:35 PM

Post #1 of 7 (1227 views)
how can we update the nameserver when the script is running Can't Post

I have a perl script that resolv domain names and print their ip addresses . The script runs on Linux. But accidently I found if i update the content of /etc/resolv.conf when the script is running, say to a invalid nameserver, this script won't pick up the new nameserver

#!/usr/bin/perl
use Socket;

print "\n".inet_ntoa(inet_aton("www.google.com"));

# now update /etc/resolv.conf with invalid nameserver
`echo "nameserver null" > /etc/resolv.conf`;

print "\n".inet_ntoa(inet_aton("www.google.com"));

Output of the script is :
66.249.89.104
66.249.89.147

In the above script the second name lookup still worked, even after the OS been told to use a invalid nameserver. So I am thinking perl remember the nameserver during the execution of the script.

Now my questoin is , how can we update the nameserver when the script is running?


data345
Novice

May 6, 2009, 12:13 PM

Post #2 of 7 (1196 views)
Re: [boliu83] how can we update the nameserver when the script is running [In reply to] Can't Post

I'm not familiar with the Socket library. And I'm one of those intermediate users that isn't that familiar with "use".

But it seems to me that
use Socket;
is loading whatever is in your /etc/resolv.conf.

Perhaps another
use Socket;
after you change the /etc/resolv.conf will cause it to load the new configuration.

I don't know if a duplicate "use" is permitted in perl or if it's mandatory to always have them at the top of the program.


(This post was edited by data345 on May 6, 2009, 12:17 PM)


KevinR
Veteran


May 6, 2009, 1:43 PM

Post #3 of 7 (1192 views)
Re: [data345] how can we update the nameserver when the script is running [In reply to] Can't Post

"use" happens at compile time so you can't "use" again later and reload a module.
-------------------------------------------------


FishMonger
Veteran / Moderator

May 6, 2009, 4:16 PM

Post #4 of 7 (1190 views)
Re: [boliu83] how can we update the nameserver when the script is running [In reply to] Can't Post

I have not done any testing, but Net::DNS::Resolver looks like it might do what you need.

http://search.cpan.org/~olaf/Net-DNS-0.65/lib/Net/DNS/Resolver.pm


boliu83
New User

May 6, 2009, 8:34 PM

Post #5 of 7 (1187 views)
Re: [data345] how can we update the nameserver when the script is running [In reply to] Can't Post

I thought in the same way initially. But useing "use Socket" twice didn't fix it.


boliu83
New User

May 6, 2009, 8:39 PM

Post #6 of 7 (1186 views)
Re: [FishMonger] how can we update the nameserver when the script is running [In reply to] Can't Post

Yes. looks like this is the only solution. but it is not very practical in my case. This script runs on more than one thousand robot computers which monitoring a very big network. Looks like I have to install this Resolver module on each of them that definitly will give me headache.


$_
Novice

May 18, 2009, 11:58 PM

Post #7 of 7 (1122 views)
Re: [boliu83] how can we update the nameserver when the script is running [In reply to] Can't Post

Maybe there could be some performance impact, but why don't you use 'host' (linux command)

@r = `host x y`;

Usage: host [-opts] hostname [server]

1. it will take the latest version of resolv.conf
2. if you actually just want to use another NS, just change [server]


(This post was edited by $_ on May 18, 2009, 11:59 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives