in reply to Simple Resolver Function

You're trying to do too much of the work yourself.
use Socket; my $address = shift or die "Usage: $0 address\n"; my $a = gethostbyname $address; $\ = $/; print defined $a ? inet_ntoa($a) : "Can't resolve '$address'";
Sample output:
% ./sample_resolver.pl Usage: ./sample_resolver.pl address % ./sample_resolver.pl 127.1 127.0.0.1 % ./sample_resolver.pl 127.54321 127.0.212.49 % ./sample_resolver.pl 3456776543 206.10.57.95 % ./sample_resolver.pl localhost 127.0.0.1 % ./sample_resolver.pl perlmonks.org 209.197.123.153 % ./sample_resolver.pl 040.030.020.010 32.24.16.8 % ./sample_resolver.pl foo.bar Can't resolve 'foo.bar' % ./sample_resolver.pl 255.0.1 255.0.0.1 % ./sample_resolver.pl 256.0.1 Can't resolve '256.0.1'

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.

Replies are listed 'Best First'.
Re: Re: Simple Resolver Function
by jbaribeault (Novice) on Mar 24, 2003 at 20:06 UTC
    Great - thanks! I think I understand more what the inet and gethost functions can do; however, your example doesn't do IP->Hostname lookups (reverse) which I needed in particular for my purposes. I needed to the know if there was a dotted-quad being looked up if there was no reverse for, not if it was just a valid ip address. Thanks for your input, this is a great place to throw around ideas!