Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net::Ping

Status
Not open for further replies.

kturner

Programmer
Mar 6, 2001
5
US
I can't get Net::ping to work.
Here is my code:

-----------------------------------------------
use Net::ping;
use Net::FTP;

$host = "hpsab4";
$timeout = 30;

use Net::ping;
$pong = Net::ping->new( $> ? "tcp" : "icmp" );

(defined $pong)
or die "Couldn't create Net::ping object: $!\n";

if ($pong->pingecho($host, 30)) {
print "It works!\n";
} else {
print "You suck!\n";
}

-----------------------------------------------------

Here is the error message:

Argument "hpsab4" isn't numeric in le at /usr/share/lib/perl5/Net/Ping.pm line 78

P.S. I get the same message if I use the IP address for the host variable.

Thanks in advance.
 

try the loopback for a start, see if you can talk to yourself first.

use Net::ping
$host='127.0.0.1';
$p = Net::ping->new("tcp", 2);
unless $p->ping($host){
[tab]print "$host: not reachable\n";
} else {
[tab]print "$host: sucess!\n";
}
undef($p);
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
I tried the suggested code.

The result was:

syntax error at ping.pl line 16, near "unless $p"
Execution of ping.pl aborted due to compilation errors.


Any suggestions/help?

Thanks again.
 
Think it should be

unless($p->ping($host)){

I missed some brackets out, sorry about that.

And, of course, there should be a semicolon after 'use Net::ping', so:

use Net::ping;
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top