CodingPHP Check if system is online

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  ANT_THOMAS  
 To:  ALL
39111.1 
I want to write a little bit of PHP to check if 2 systems on my network are online.

Currently I've used this
php code:
$output = shell_exec('ping -n 1 192.168.1.90');
echo "<pre>$output</pre>";

and it just shows the ping output. It works, does the job, but it's ugly.

code:
Pinging 192.168.1.90 with 32 bytes of data:
Reply from 192.168.1.90: bytes=32 time<1ms TTL=64
 
Ping statistics for 192.168.1.90:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms


Any better suggestions?

Something to give

192.168.1.90 - Online
or Offline
0/0
 Reply   Quote More 

 From:  Dan (HERMAND)  
 To:  ANT_THOMAS     
39111.2 In reply to 39111.1 

This?

 

http://stackoverflow.com/questions/1239068/ping-site-and-return-result-in-php

0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Dan (HERMAND)     
39111.3 In reply to 39111.2 
I'm currently using the last suggestion on there, should really try the earlier ones too.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
39111.4 In reply to 39111.3 
quote:
the last suggestion on there

The "last" on depends on how you're sorting them, which may well be different to the rest of us.


Here's the code used at backup.tehforum.co.uk - no idea if it's the best or even a good way of doing it, but it works well enough:
php code:
<?php
	function ping($host, $port, $timeout)
	{
		$tB = microtime(true);
		$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
		if (!$fP) { return '<strong style="color: red;">failed</strong>'; }
		$tA = microtime(true);
		return '<strong style="color:green;">success in '.round((($tA - $tB) * 1000), 0).' milliseconds</strong>';
	}
?>
 
<p>Pinging 178.79.137.101... <? echo @ping("178.79.137.101", 80, 10); ?>.</p>
 
<p>Pinging www.tehforum.co.uk... <? echo @ping("www.tehforum.co.uk", 80, 10); ?>.</p>
 
<p>Verifying forum is online...<?
	if (strpos(strtolower(file_get_contents("http://www.tehforum.co.uk/forum")),'<title>teh forum</title>') !== false)
	{
		echo '<strong style="color:green;">success</strong>';
	}
	else
	{
		echo '<strong style="color:red;">failed</strong>';
	}
?>.</p>
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
39111.5 In reply to 39111.4 

Well I did quote the one I've used in the first post....

 

And thanks for Teh Backup code, I shall give that a go :D

0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  ANT_THOMAS     
39111.6 In reply to 39111.5 
Damn it, ping doesn't work with my Windows Apache server.
0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)  
 To:  ANT_THOMAS     
39111.7 In reply to 39111.6 
quote:
doesn't work with my Windows


the rest is redundant...

----
We invented pablum.
0/0
 Reply   Quote More 

 From:  Lucy (X3N0PH0N)  
 To:  ANT_THOMAS     
39111.8 In reply to 39111.6 
If it's a web server you want to check then why not just use file() or file_get_contents() to try to retrieve something you know to be there?

(This may be bad practise, I dunno)
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Lucy (X3N0PH0N)     
39111.9 In reply to 39111.8 
If I can't get a ping solution working I might have to install some webserver on the two systems in question and use the method you suggest. They're both running ubuntu and one is a VM, so to be honest that one probably doesn't really need to be checked.
0/0
 Reply   Quote More 

Reply to All    
 

1–9

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats