Added regex to determine if packet loss is 0%

Accepts:
0
0.0
0.00
0.000
0,0
0,00
0,000
This commit is contained in:
TimZ99 2020-05-18 20:27:11 +02:00
parent 59f434ca4c
commit 500860daf3
No known key found for this signature in database
GPG Key ID: 4D8268DC68E8339D
1 changed files with 3 additions and 1 deletions

View File

@ -190,7 +190,9 @@ class StatusUpdater
$txt = exec($pingCommand . " -c" . $max_runs . " " . $serverIp . " 2>&1", $output);
// Check if output is PING and if 0,0% of packages are lost, otherwise fail.
if (substr($output[0], 0, 4) == 'PING' && strpos($output[count($output) - 2], '0.0% packet loss')) {
preg_match('/([0][,.]?0{0,3})(% packet loss)$/', $output[count($output) - 2], $output_package_loss);
if (substr($output[0], 0, 4) == 'PING' && count($output_package_loss) !== 0) {
// Gets avg from 'round-trip min/avg/max/stddev = 7.109/7.109/7.109/0.000 ms'
preg_match_all("/(\d+\.\d+)/", $output[count($output) - 1], $result);
$result = floatval($result[0][1]);