From 9e2a4ec3c5d92e1f3134efc111286237e690f513 Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Sat, 15 Feb 2020 16:13:32 +0100 Subject: [PATCH] Fixed RegExp - Current Ubuntu seems to have dropped the 'addr:' string from the `ifconfig` output --- src/Datasift/IfconfigParser/Base.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Datasift/IfconfigParser/Base.php b/src/Datasift/IfconfigParser/Base.php index aaaeea3..2b1cd32 100644 --- a/src/Datasift/IfconfigParser/Base.php +++ b/src/Datasift/IfconfigParser/Base.php @@ -64,7 +64,7 @@ public function getDelimiter() { * @return string */ public function getRegex(){ - return "^(?(?:[^\s]+)).*?(?:inet addr:(?(?:\d+\.?){4})|$)"; + return "^(?(?:[^\s]+)).*?(?:inet (?:addr:)?(?(?:\d+\.?){4})|$)"; } /** @@ -72,13 +72,13 @@ public function getRegex(){ * * @param mixed $input ifconfig input to parse * - * @return string + * @return array */ public function parse($input){ - $adapters = preg_split("/" . $this->getDelimiter() . "/s", $input, null); + $adapters = preg_split('/' . $this->getDelimiter() . '/s', $input, null); $vals = array(); foreach ($adapters as $int){ - preg_match("/".$this->getRegex()."/s", $int, $output); + preg_match('/' . $this->getRegex() . '/s', $int, $output); $vals[] = $output; } @@ -97,7 +97,7 @@ protected function format($vals){ $formattedVals = array(); $expectedFields = array( - "interface", "ip_address" + 'interface', 'ip_address' ); foreach ($vals as $v){ @@ -112,7 +112,7 @@ protected function format($vals){ } // Remove any entries that don't have an interface - $formattedVals = array_filter($formattedVals, function($val){ + $formattedVals = array_filter($formattedVals, static function($val){ return isset($val['interface']); });