in reply to gethostbyname not working
As you will see in the docs, gethostbyname returns a list, the last element of which is the IP address in packed format. You'll need to unpack it first, like so:
my $hostname = 'yahoo.com'; my $addr = (gethostbyname($hostname))[4]; # Or, as Anonymous Monk points out below, you could simply use: # my $addr = gethostbyname($hostname); my ($a,$b,$c,$d) = unpack('C4',$addr); print "$a.$b.$c.$d\n";
Update: Corrected which element of gethostbyname returns the address.
Update 2: Added AM's advice.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: gethostbyname not working
by Anonymous Monk on Mar 27, 2001 at 02:32 UTC | |
by nick (Sexton) on Mar 27, 2001 at 03:54 UTC | |
by Clownburner (Monk) on Mar 27, 2001 at 20:35 UTC | |
by Anonymous Monk on Mar 27, 2001 at 04:35 UTC | |
by myocom (Deacon) on Mar 27, 2001 at 03:10 UTC | |
|
Re: Re: gethostbyname not working
by nick (Sexton) on Mar 27, 2001 at 02:14 UTC | |
by tadman (Prior) on Mar 27, 2001 at 23:19 UTC | |
by myocom (Deacon) on Mar 27, 2001 at 02:18 UTC |