http://qs321.pair.com?node_id=652185


in reply to Short pinging script isn't working

I ran this on Windows (XP Pro) with ActiveState Perl 5.8.8 and it worked just by changing the target to my local host. Do you have the Windows firewall running?

As far as the timeout goes, you already have it in your call to the 'ping' function:

$p->ping($target, 2)
gives a 2 second timeout. Or as jbert pointed out ('ctor' means 'constructor' means Net::Ping->new), you can specify the timeout in your 'new' call.

To repeat every 5 seconds I think you have to get outside Net::Ping. Here's a rough untested estimate of one way to do it without even trying to take into account the time that it actually takes to do the ping:

while (1) { $p->ping($target, 2); sleep 5; }

After that, if you want to initiate the ping on every fifth second you could try Schedule::Cron. Then, when you get tired of reinventing the monitoring wheel, install Nagios for some serious pinging that can result in an annoying sound coming from your pager at 2AM.