Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: DNS Resolution4

by tinman (Curate)
on Apr 25, 2001 at 02:58 UTC ( #75309=note: print w/ replies, xml ) Need Help??


in reply to DNS Resolution4

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


Comment on Re: DNS Resolution4
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://75309]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-07-31 02:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls