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!

See if a system is up and running..

Status
Not open for further replies.

klibby

Programmer
May 30, 2001
51
0
0
US
I'm not sure if this is possible with Perl... but is there any way to take an IP address of a system running a web server and see if it is up or down, then return that to the Perl script so it can do something for whether it is up or down?
 
Not really. But there is abotehr module that could do similar.

use Net::ping;

if ( pingecho(" 15) ) {
print "Yahoo webserver is rechable!";
}else{
print "Yahoo is unreachable!";
}

Net::ping will check to see if the system is running. If it is, it sends a reply.
-Aaron
 
Man, i better check my spell check. It's suppose to be *another* not abotehr :) -Aaron
 
ahh cool.... do you know where I can get that mod?
 
If you have perl version 5 installed, it's already came with that. So you don't actually need to download the module. -Aaron
 
Thank you Aaron, I have one question though... what exactly is the 15 in the little piece of code you gave me?....

I tried the following code just to test...

if (pingecho(" 15) ) {
print "SERVER IS UP";
}else{
print "SERVER IS DOWN";
}


that returned a 500 error, so i got rid of the ";" after the "eqguardians.com" and left the comma and tried that.. it didnt return a 500 error but returned the "server is down" message when the server was really up...

I just figured, knowing what the 15 was might help hehe
 
use Net::ping;

if ( pingecho(" ", 15) ) {
print "Yahoo server is up!";
}else{
print "Whoops, server is unreachable!";
}

The first is a host to find- in this case. The second, 15 is the seconds indicates how long pingecho should wait for a response in seconds. Hope this helps.


-Aaron
 
ok.. it looks like the code is working.... however, it keeps returning the server is DOWN message no matter whether the system is really up or down, I tried like in your example, tried my IP address, and tried (my own domain where I tried the script)... then just to make sure i wasnt switching the two messages, I tried to see if it would return server is UP message.. still says down... so its saying down no matter what... any ideas?
 
hmm.. actually, I may know the problem.... but dont know how to get arround it..... I noticed, even when I try a timeout of say 50, the script will load up on my browser and display the down message fast.. (a few seconds or less)... so, though in that test when i gave it a 50 second timeout... it wasnt waiting for the timeout, it was simply going through and executing the code without even waiting for a reply.... any way to fix this?
 
wow, fast response hehe thanks for all your help =)
 
Hey, I dont really know, but wouldnt that number be in millisecs? and 15-50 millisecs is way too short to wait for a ping... try like 1000. If it were really 15 secs you were waiting, then it should take 15 secs for the script to print "server is down"
 
nope, it is in seconds... but i tried using up to 15000 for timeout anyway hehe.. still said it was down, still didnt take any time to load
 
There's an alternative format for Net::ping that I like to use as well, which may yield better results for you. This is an excerpt from a script I use to, as you said, see if a machine is up or down. This (part of the code - don't ask about the rest :( ) runs great in Windows 2000, but I haven't tested it in *nix.
Code:
$p = Net::Ping->new("$protocol_choice");
 if ($p->ping($node, $timeout))
  { 		
   print "$node is pingable \n"; 
  }
 else 
  {
   print "$node is \*NOT\* pingable \n"; 
  }
$p->close();
The timeout is in seconds, and the protocols are the standard TCP, ICMP, and UDP. The default protocol is UDP, and the default timeout is 5 seconds. I think I remember seeing something in the perl documentation from Activestate that said pingecho was obsolete, which could be part of the problem. Hope I'm not too late to be of help. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top