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

Hi,

I need to retrieve all ip addresses for a specified host. In C, this would be easy as I would just run gethostbyname() and loop through the HOSTRECs obtaining all ip addresses that were registered with the name service (dns, hosts, ldap, etc.). The Socket retrieves the first HOSTREC and the IO::Socket modules perform the basically the same thing but seem to require or implement connections to the remote site.

All I want to do is obtain all the ip addresses from from the HOSTRECs that are produced by gethostbyname() (c version not Socket:: version)

This must have been asked before but the only references I've seen deal with obtaining the ip addresses of the local machine.

thanks
Jason

Replies are listed 'Best First'.
Re: host with multiple ip addresses
by pg (Canon) on Dec 03, 2003 at 19:54 UTC

    In Perl, it is the same thing, just call gethostbyname. There is no need to connect to the remote.

    You talk to DNS and not the remote to get the ip address.

    If my PC is called "blah", I just do:

    gethostbyname("blah");
Re: host with multiple ip addresses
by mpeppler (Vicar) on Dec 03, 2003 at 19:55 UTC
    Have you tried using the "raw" gethostbyname() call in perl (see perldoc perlfunc). I think that should return what you want:
    ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($name);
    Michael