Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://75309]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2016-12-03 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (59 votes). Check out past polls.