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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |