Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Short pinging script isn't working

by andyford (Curate)
on Nov 21, 2007 at 17:52 UTC ( #652185=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://652185]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2022-05-27 16:50 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (97 votes). Check out past polls.