This works for me on Win32 ActivePerl

#/usr/bin/perl -w use strict; use Socket; my $host = "www.yahoo.com"; my @addresses = gethostbyname($host) or die "Can't resolve $host: $! +\n"; @addresses = map { inet_ntoa($_) } @addresses[4 .. $#addresses]; print "The next set is @addresses \n";

No credit to me.. this is a snippet that I got from some book or the other.. but I use it and it works for me

The following is the complete code for both ways..

#/usr/bin/perl -w use strict; use Socket; my $host = "www.yahoo.com"; my $packed_ip = gethostbyname($host) or die "Unable to resolve '$host'\n"; my $ipaddr = inet_ntoa($packed_ip); print "$ipaddr for $host\n"; my $packed_add = gethostbyaddr($ipaddr, AF_INET); my $hostname = inet_aton($packed_add) or die "Can't reverse lookup \n" +; print "The host name for $ipaddr is $hostname \n"; my $name = "www.perl.com"; my @addresses = gethostbyname($host) or die "Can't resolve $name: $! +\n"; @addresses = map { inet_ntoa($_) } @addresses[4 .. $#addresses]; print "The next set is @addresses \n";

Try this posting for a much easier way of doing it.. Net::DNS
Update: Fixed tyop :)
Update 2: Gave both forward and reverse lookup code


In reply to Re: DNS Resolution4 by tinman
in thread DNS Resolution4 by muaddib2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.