Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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.


Comment on Re: Short pinging script isn't working
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2014-12-26 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls