From 397ae63e3c612e23228308108f64e9fb818f6c8a Mon Sep 17 00:00:00 2001 From: HouraisanNEET Date: Tue, 1 Jun 2021 16:44:04 +0800 Subject: Catch RuntimeException Signed-off-by: HouraisanNEET --- lib/OperatingSystems/FreeBSD.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/OperatingSystems/FreeBSD.php b/lib/OperatingSystems/FreeBSD.php index 6ef4cfb..1651e82 100644 --- a/lib/OperatingSystems/FreeBSD.php +++ b/lib/OperatingSystems/FreeBSD.php @@ -17,7 +17,7 @@ declare(strict_types=1); * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see + * along with this program. If not, see * */ @@ -150,13 +150,24 @@ class FreeBSD implements IOperatingSystem { public function getNetworkInterfaces(): array { $result = []; - $ifconfig = $this->executeCommand('/sbin/ifconfig -a'); + try { + $ifconfig = $this->executeCommand('/sbin/ifconfig -a'); + } catch (\RuntimeException $e) { + return $result; + } + preg_match_all("/^(?<=(?!\t)).*(?=:)/m", $ifconfig, $interfaces); foreach ($interfaces[0] as $interface) { $iface = []; $iface['interface'] = $interface; - $intface = $this->executeCommand('/sbin/ifconfig ' . $iface['interface']); + + try { + $intface = $this->executeCommand('/sbin/ifconfig ' . $iface['interface']); + } catch (\RuntimeException $e) { + continue; + } + preg_match_all("/(?<=inet ).\S*/m", $intface, $ipv4); preg_match_all("/(?<=inet6 )((.*(?=%))|(.\S*))/m", $intface, $ipv6); $iface['ipv4'] = implode(' ', $ipv4[0]); -- cgit v1.2.3