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

Hi all. I'm a newbie,so if this question can be answered with a page on this site or a chapter in the camel book, please tell me. Ok. I want to write a little script that will connect to a DNS server and feed it the names of user provided websites to get the IPs. I know that I'm going to be calling nslookup, but my question is: once I have the IP of the DNS server, how do I connect to it? Do I have to pipe commands to it, or somehow route nslookup to that Handle, or will it just automatically send it to said DNS server once I have connected? Your help would be much appreciated. Thanks in advance.

Replies are listed 'Best First'.
Re: A little network question
by arhuman (Vicar) on Apr 25, 2001 at 16:29 UTC
    You'll find the light with :

    perldoc Net::DNS
    or
    perldoc perlfunc (see gethostbyaddr)
    or
    SuperSearch (which gave me this node)

    And I'd be glad to help on a more specific question ;-)


    "Only Bad Coders Badly Code In Perl" (OBC2IP)
Re: A little network question
by KM (Priest) on Apr 25, 2001 at 16:33 UTC
    Look at Net::DNS. I have also used Email::Valid, which will use either Net::DNS (if installed) or do the nslookup (if Net::DNS isn't installed). The code in both modules maybe an interesting read to you.

    Also, 'perldoc -f gethostbyaddr' is good reading.

    Cheers,
    KM

Re: A little network question
by derek3000 (Beadle) on Apr 25, 2001 at 16:53 UTC
    to the two monks who answered my question: thanks a lot. I'm sure I'll have more questions later, but since the perl community is so cool, I won't be afraid to ask. I'm already trying to convince my co-workers to convert after I converted from C to perl-sites like this are one of the main reasons. So thanks again for the help--it means more than you might think!
Re: A little network question
by hdp (Beadle) on Apr 25, 2001 at 18:52 UTC
    Your question makes me wonder if I'm missing something. Specifying a nameserver instead of using things like gethostbyname and letting the OS do the lookups for you on whatever servers it's configured to use can lead to problems. For example, if your nameservers change, you now have one additional place you need to remember to change that information, and if you move this script to a different machine, you'll likely need to update it again.

    This is not to say there are no valid reasons for doing so, but none are coming readily to my mind.

    hdp.

      Maybe this will answer that last one: I came up with this idea yesterday because the name server here went down, as it does many times. It was frustrating to me because I knew that if I had the IPs of the sites, I would at least be able to do some surfing (work is boring, and also a bitch because our air conditioning wasn't ready yet--yesterday was 80 something here). So I thought that a great way to apply what I've learned so far would be to write a little script to fetch the IPs from an alternate nameserver. Is this kind of a weird reason? Probably. But this was more of an excercise than anything.