Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: is there script to detect if remote machine is alive/reachable w/o using Net::Ping?

by ehdonhon (Curate)
on Jun 06, 2002 at 23:35 UTC ( [id://172391]=note: print w/replies, xml ) Need Help??


in reply to is there script to detect if remote machine is alive/reachable w/o using Net::Ping?

Im currenlty using a Redhat Linux and the PING command there seems to also "HANG" on unreachable machines

Did you specify a timeout period for ping? You can use -t to tell ping when you want it to exit. Here's some code that returns true if the remote machine pings at least once in 7 seconds:

sub ping { my $ip = shift; my $p = `/sbin/ping -c 5 -t 7 $ip | /usr/bin/grep 'packet loss'`; unless ( $p =~ /(\d+)% packet loss/ ) { die ( "Bad Response:\n$p\n" ); } my $loss = $1; print "Loss = $1 "; return ( $loss != 100 ); }

  • Comment on Re: is there script to detect if remote machine is alive/reachable w/o using Net::Ping?
  • Download Code

Replies are listed 'Best First'.
Re: Re: is there script to detect if remote machine is alive/reachable w/o using Net::Ping?
by perigeeV (Hermit) on Jun 07, 2002 at 00:41 UTC

    Are you on RedHat? iputils-ss001110 uses -t for time-to-live. I've got -w for timeout. Oh well, no matter.


      tnx very much guys! i really appreciated the help. even though my question was not specific. im really sorry about it. my question shouldve been like this:
      In general IO::Socket process (regardless of which socket and what typ +e of socket to use) what should be the recommended process to detect +if the remote machines are alive/reachable if you dont want to put a +DIE command after the IO::Socket::INET->new() process? (of course, to + avoid HANG and probably you would have other codes to execute after +the socket connect process...)
      The only thing I thought about at that time was PING. And yes I did forget to check the man pages, sorry for that. heres what i did.:
      sub doit { $host="$aa.$bb.$cc.$dd"; $port="23"; $fnd=""; $pong=`ping -c 3 $host -v`; #is there really a "-t" option here? $fnd=($pong=~m/(...)%/gi); $xcd=$1; if ($xcd!=100) { $remote = IO::Socket::INET -> new ( Proto => "tcp", PeerAddr => $host, PeerPort => $port, Timeout => 1 ); $| = 1; if ($remote) { close $remote; print "Socket ready..."; } else { print "Try again!"; } } }
      tnx really a lot for helping me. but i do have one inquiry though. "Is there a way to detect remote machines if they are alive/reachable w/o using NET::Ping and the shell command /sbin/ping?" Hopefully something like a socket command. thank you very much to all those who helped me. Lovelots and *mwah*, Cherry.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-25 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found