in reply to Finding hostname aliases

One way to get some aliases is to use Net::hostent. Here is an example from the manpage:
use Net::hostent; use Socket; @ARGV = ('netscape.com') unless @ARGV; for $host ( @ARGV ) { unless ($h = gethost($host)) { warn "$0: no such host: $host\n"; next; } printf "\n%s is %s%s\n", $host, lc($h->name) eq lc($host) ? "" : "*really* ", $h->name; print "\taliases are ", join(", ", @{$h->aliases}), "\n" if @{$h->aliases}; if ( @{$h->addr_list} > 1 ) { my $i; for $addr ( @{$h->addr_list} ) { printf "\taddr #%d is [%s]\n", $i++, inet_ntoa($add +r); } } else { printf "\taddress is [%s]\n", inet_ntoa($h->addr); } if ($h = gethostbyaddr($h->addr)) { if (lc($h->name) ne lc($host)) { printf "\tThat addr reverses to host %s!\n", $h->na +me; $host = $h->name; redo; } } }

-Mark

Replies are listed 'Best First'.
Re: Re: Finding hostname aliases
by liz (Monsignor) on Sep 12, 2003 at 08:01 UTC
    And then there are wildcard DNS records. Try the above code (assuming the script is called "resolve") with:
    $ perl resolve www.startpagina.nl
    which gives:
    www.startpagina.nl is www.startpagina.nl addr #0 is [62.69.162.8] addr #1 is [62.69.162.6] addr #2 is [62.69.162.7]
    All nice and good, you would say. You get 3 IP-numbers and it resolves back correctly. Now you want to find all the aliases to "www.startpagina.nl". Try this by doing:
    $ perl resolve anythingyoucanthinkof.startpagina.nl
    which generates this output:
    anythingyoucanthinkof.startpagina.nl is anythingyoucanthinkof.startpag +ina.nl addr #0 is [62.69.162.7] addr #1 is [62.69.162.8] addr #2 is [62.69.162.6] That addr reverses to host www.startpagina.nl! www.startpagina.nl is www.startpagina.nl addr #0 is [62.69.162.8] addr #1 is [62.69.162.6] addr #2 is [62.69.162.7]
    Now replace "anythingyoucanthinkof" with anything else you can think of. Then meditate on the number of aliases "www.startpagina.nl" has. ;-)

    Hope this helps.

    Liz
      Thanks for all the pointers - now understand a lot more about how to properly use Net::hostent. However, my problem still remains. For instance, if I use the code snippet supplied my shenme, I get exactly the output promised. But my problem is that I would like to be able to give 'a562.cd.akamai.net' as the argument and have it return 'www.microsoft.com' as an alias. Alas, this does not happen and it appears that this is indeed the way this module (Net::hostent) is intended to work. So I am still wandering in the dark :( Thanks for all your efforts - Mark
        Hope this analogy will help you get out of the dark.

        "a562.cd.akamai.net" is a description of how to get to one or more IP-numbers (Rome).
        "www.microsoft.com" is another description to get to the same IP-number(s) (Still Rome).

        You're asking, given "Rome", to be able to tell all the possible ways to Rome. There could be one, there could be thousands. You won't be able to find out from "Rome". There is no way to know, unless you start trying them out one by one (in a Shakespeare monkey manner).

        Another analogy. You call yourself "marknm". But can you know what other people call you unless they tell you? No. Not unless your psychic. And even that could be considered them telling you what they call you.

        Hope this clears things up.

        Liz

Re: Re: Finding hostname aliases
by shenme (Priest) on Sep 11, 2003 at 23:41 UTC
    Works for me, along with the original gethostbyname().
    use Net::hostent; my $h = gethost( 'www.microsoft.com' ); # name aliases addrtype length addr_list my @aliases = @{ $h->aliases }; printf " Name '%s'\n", $h->name; printf " Aliases are '%s'\n", join("', '", @aliases );
    Output:
      Name  'a562.cd.akamai.net'
      Aliases are 'www.microsoft.com', 'www.microsoft.com.edgesuite.net'