kleinbiker7 has asked for the wisdom of the Perl Monks concerning the following question:

How do I call nslookup in Perl? What I need to do is the following to verify that these URLS are good:

nslookup
server ns1.abs.net
www.cnn.com

server ns2.idi.net
www.cnn.com

server ns3.idi.net
www.cnn.com

etc

My Perl script tries to call nslookup like this:

system ("nslookup; server ns1.abs.net; gunfreekids.org");
but it only starts nslookup, it doesnt run the other stuff. How can I get Perl to run the other stuff as well?

Thanks
Robert

Replies are listed 'Best First'.
Re: How do I get Perl to run nslookup?
by suaveant (Parson) on May 08, 2001 at 21:20 UTC
    The easiest way to do it is pass the info in on the commandline, instead of trying to run the commands in interactive mode (which can be done, but involves much more work) for all the options to nslookup, do man nslookup, but on my system you do 'nslookup host server' so your first example would be
    $response = `nslookup gunfreekids.org ns1.abs.net`;
    it is usually goo to give the full path of your executable, though, such as /usr/bin/nslookup
                    - Ant
      Hey suaveant, Thanks for your excellent response. I ran the idea with my boss, and she likes the idea. It also produces less red-tape from UNIX than my previous example. Will definately ask you, or the other gurus for help, should the problem arise. Robert
        No problem...

        many unix utils have command-line utils so they can be called from scripts or as an alias, but if all else fails you need a package like Expect which pretends to be a user, basically...
                        - Ant

Re: How do I get Perl to run nslookup?
by Anonymous Monk on May 08, 2001 at 21:27 UTC
    While a pipe might work, you may want to look into Net::DNS::Resolver which allows you to specify the nameservers. Or you could use gethostbyname() if you don't need to specify the nameserver.