On Thu, 24 Feb 2000 17:40:20 you wrote:
>
> Anyway, I have a Perl script, using Net::Ping, etc., and it doesn't seem
> to be working. I am not a PERL guru, obviously.
> my $rtn = $pg->ping(\$sname);
> returns zero.
>
First off, your passing a reference to the ping method...
its supposed to take a simple scalar value. The correct way to do it is:
my $rtn = $pg->ping($sname);
(notice there is no backslash before $sname)
> my $saddr = gethostbyname($sname);
> printf "\n%s: 0x%X\n", $sname, $saddr;
> if ($saddr == 0) {
> print "address is zero\n";
> }
> else {
> printf "Actual address is:$i\n", $saddr;
> };
gethostbyname actually returns the following in array context:
($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($sname);
However, you've called it in scalar context. In that case it returns
just the host address. If you want the IP address of the host, here
is an easy way to get it:
my $IP = join(".", unpack('C4', gethostbyname($sname) ));
To explain this a little, gethostbyname doesn't return a nice readable
IP address like you want. Instead it returns a binary structure
consisting of 4 unsigned chars. The unpack takes the binary structure
and turns it back into 4 (hence C4) nice scalar values. The join simply
puts it all together into a nice "normal" IP address.
Hope that helps.
-Matt
**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************