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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my ping function not detecting live hosts!!!

Status
Not open for further replies.

MermaidGaby

Programmer
Feb 19, 2003
1
0
0
US
Everytime I try to ping live hosts with this code, I get the incorrect output ("not alive"). Why is it that it is not detecting live hosts. I know I may be making a dumb mistake, but, be nice, I am new to perl.

<code>
#use Net::ping perl library
use Net::ping;
#Create a new ping object
#$p=Net::ping->new();
$host=&quot;localhost&quot;;
$p = Net::ping->new();
if ($p->ping($host))
{print &quot;$host is alive.\n&quot;;}
else
{print &quot;not alive.\n&quot;;}
$p->close();
</code<
 
It's possible that your localhost doesn't have its udp echo port open. Net::ping uses the udp protocol by default, and it sends packets to the echo port of the queried host. If you have root privileges try an 'icmp' ping instead. 'Most' hosts will respond to an icmp echo request.

jaa
 
Something I noticed when I used Net::ping was that Unix(linux) and Windows machines respond differently. As Justice41 said, it may be a difference between echo and ICMP. I worked around this by pinging the machine with echo first and then ICMP. And if both of them fail, I marked them as down. Hope this was helpful.

- V.
 
Gaby,

Use another ping type -- try tcp, that should fix things. Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top