round robin dns's and ip addresses

Kevin Darcy kcd at daimlerchrysler.com
Sat Aug 13 00:06:31 UTC 2005


yawnmoth wrote:

>If a particular domain is using a round robin DNS and has 2+ IP
>addresses associated with it, is there any way I could get a list of
>all the IP addresses associated with the domain?  gethostbyname will
>return one IP address, but I'd like all of them...
>
>PHP has a function - gethostbynamel - that looked useful, but it, too,
>only returns one IPaddress...
>
What OS are you using? On all (Unix-like) OSes I know, gethostbyname() 
returns a struct hostent, which contains a *list* of IP addresses, not 
just a single address, e.g.

    struct hostent {
         char    *h_name;         /* canonical name of host */
         char    **h_aliases;     /* alias list */
         int     h_addrtype;      /* host address type */
         int     h_length;        /* length of address */
         char    **h_addr_list;   /* list of addresses */
     };

Failing that, use Perl and the Net::DNS module, which makes it fairly 
trivial to find all of the A records (just loop through all the "rr" 
objects in the "answer" array, which is a member of the "packet" object 
that was returned by your query, looking for ones with "type" set to "A").

                                                                         
                                                   - Kevin




More information about the bind-users mailing list