Folgende Funktion führt einen Ping auf die angegebene IP-Adresse ($ip) aus und liefert die Ping-Zeit zurück. Sollte die IP nicht erreichbar sein, wird 0.0 zurückgegeben.
Hinweis: Damit diese Funktion funktioniert, muss shell_exec auf dem Server erlaubt sein
function ping($ip) { if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') $command = shell_exec('ping -n 1 '.$ip); else $command = shell_exec('ping -c 1 '.$ip); if(eregi('100%', $command)) { return '0.0'; } else { $start = strpos($command, 'time=') + 5; $ende = strpos($command, 'ms'); $mstime = substr($command, $start, $ende-$start); return $mstime; } } else { return '0.0'; } }