devices[$entry] = new NetworkInterface($entry); } $result = shell_exec('ip --json address show'); foreach(json_decode($result) AS $entry) { $device = $this->devices[$entry->ifname]; //$device->debug = $entry; if(isset($entry->link_type)) { $device->setType($entry->link_type); } if(isset($entry->operstate)) { $device->setState(NetworkState::tryFromName($entry->operstate)); } if(isset($entry->address)) { $device->setAddress($entry->address); } if(isset($entry->broadcast)) { $device->setBroadcast($entry->broadcast); } } } public function getDevices() : array { return $this->devices; } public function getHostname() : string { return trim(shell_exec('hostname')); } public function getPanelHostname() : string { return trim($_SERVER['HTTP_HOST']); } public function getIPAddress() : string { return trim($_SERVER['SERVER_ADDR']); } public function getDevice($id) : NetworkInterface | null { return $this->devices[$id]; } } class NetworkInterfaces { public static function get() : ?NetworkInterfacesFactory { return NetworkInterfacesFactory::getInstance(); } public static function getDevices() : array { return NetworkInterfacesFactory::getInstance()->getDevices(); } public static function getHostname() : string { return NetworkInterfacesFactory::getInstance()->getHostname(); } public static function getPanelHostname() : string { return NetworkInterfacesFactory::getInstance()->getPanelHostname(); } public static function getIPAddress() : string { return NetworkInterfacesFactory::getInstance()->getIPAddress(); } public static function getDevice($id) : NetworkInterface | null { return NetworkInterfacesFactory::getInstance()->getDevice($id); } } ?>