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.

blueyoda

Programmer
Sep 15, 2000
3
FR
Hello,

I'm using the Net::ping module so as to test if a server can be link.

But with any servers, the system ping tell me the server is alive, therefore the Net::ping answer me the server can't be linked.

Thanck you for helping me.
 
I'll rephrase your question first, just in case i'm misinterpreting it:
Net::ping tells me if a server is alive.
How can i tell that it cannot be reached?

If this is your questing, the answer is:

[tt]$p = Net::ping->new();
print "$host is alive.\n" if $p->ping($host);
$p->close();
[/tt]
that is, the return of ping() determines if it can be reached or not.
returns 1 means it can be reached.
returns 0 means it cannot be reached.

If that was not your question, please enter it again to clear up any discrepancies.

"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Hello,

My trouble is the following :
I want to know if I can reach the server named "toto".
The system ping (ping toto) answer me : "toto is alive"

$serveur = "toto";
$p = Net::ping->new();
$p->ping($serveur); answer me : "toto is unreachable"
$p->close();

So, I don't undestand why the answer from perl and system is different.

Thanck you for helping me.
 
Ah, so Net::ping is failing. I don't know that it has any particular failings. It may be you need to format the name differently when supplying it to the Ping function. Another easier solution might be to use the system command:
[tt]
$p = system "ping toto";
[/tt]
but the return value will be weird for system(look it up in the perldocs to make sure you interpret it correctly, or even find the source in Net::ping that does the interpreting on it's own).
that's my best guess; hope it helps.
"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
I've had trouble with Net::ping before now and worked around it like this.

Specify the protocol type when you call new(), like this:

$p = Net::ping->new("icmp");

or

$p = Net::ping->new("tcp");

or

$p = Net::ping->new("udp");

I've never been able to get icmp to work....
Mike
michael.j.lacey@ntlworld.com
 
That's strange... i'll read the known bugs on Net::ping, and you might want to as well.
Are you able to work with the system("ping") contruct?
What system are you working on?
...
"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top