From b346cd9c4d64183b4b201c32b60c4c7a05c2197d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Gomes=20da=20Silva=20Lisboa?= Date: Sun, 19 Apr 2020 09:41:29 -0300 Subject: [PATCH] Fixed fail to ping IPv6 #879 (#880) Fixes #879. --- .gitignore | 2 ++ src/psm/Util/Server/Updater/StatusUpdater.php | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7118155f..e1c85147 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ *.bak __MACOSX/ .DS_Store +.buildpath +.settings/ diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index 22bcab59..6d6ff34b 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -180,7 +180,12 @@ class StatusUpdater } $result = null; // Execute ping - $txt = exec("ping -c " . $max_runs . " " . $this->server['ip'] . " 2>&1", $output); + $pingCommand = 'ping6'; + $serverIp = $this->server['ip']; + if (filter_var($serverIp,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false){ + $pingCommand = 'ping'; + } + $txt = exec($pingCommand . " -c " . $max_runs . " " . $serverIp . " 2>&1", $output); // Non-greedy match on filler $re1 = '.*?'; // Uninteresting: float @@ -192,7 +197,9 @@ class StatusUpdater if (preg_match_all("/" . $re1 . $re2 . $re3 . $re4 . "/is", $txt, $matches)) { $result = $matches[1][0]; } - + if (substr($output[0],0,4) == 'PING' && strpos($output[count($output)-2],'packets transmitted')){ + $result = 0; + } if (!is_null($result)) { $this->header = $output[0]; $status = true; @@ -225,7 +232,11 @@ class StatusUpdater // save response time $starttime = microtime(true); - $fp = @fsockopen($this->server['ip'], $this->server['port'], $errno, $this->error, $timeout); + $serverIp = $this->server['ip']; + if (filter_var($serverIp,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false){ + $serverIp = "[$serverIp]"; + } + $fp = @fsockopen($serverIp, $this->server['port'], $errno, $this->error, $timeout); $status = ($fp === false) ? false : true; $this->rtime = (microtime(true) - $starttime);