urn:schemas-upnp-org:device:WANDevice:1 WANDevice MiniUPnP http://miniupnp.free.fr/ WAN Device WAN Device 20161205 http://miniupnp.free.fr/ 00000000 uuid:ea80ec5e-2ff9-4834-866a-257fccd9e572 000000000000 */ use SimpleXMLElement; class Device { protected $deviceType; protected $friendlyName; protected $manufacturer; protected $manufacturerUrl; protected $modelName; protected $modelDescription; protected $modelNumber; protected $modelUrl; protected $serialNumber; protected $specUrl; protected $services = []; protected $devices = []; public static function createFromSchema($url, $ip) { $xml = simplexml_load_file($url); $spec = $xml->children('urn:schemas-upnp-org:device-1-0'); if (count($spec)>0) { $device = $spec->device; return new Device($device, $url, $ip); } } public function __construct(SimpleXMLElement $spec, $spec_url, $ip) { $this->ip = $ip; $this->specUrl = (string)$spec_url; $this->deviceType = (string)$spec->deviceType; $this->friendlyName = (string)$spec->friendlyName; $this->manufacturer = (string)$spec->manufacturer; $this->manufacturerUrl = (string)$spec->manufacturerURL; $this->modelName = (string)$spec->modelName; $this->modelDescription = (string)$spec->modelDescription; $this->modelNumber = (string)$spec->modelNumber; $this->modelUrl = (string)$spec->modelURL; $this->serialNumber = (string)$spec->serialNumber; $devices = $spec->deviceList; if (count($devices)>0) { foreach ($devices->children() as $device) { $this->devices[] = new Device($device, $spec_url, $ip); } } $services = $spec->serviceList; if (count($services)>0) { foreach ($services->children() as $service) { $this->services[] = new Service($service); } } } public function getIp() { return $this->ip; } public function __toString() { $info = sprintf("Device: %s [%s] at %s\nManufacturer: %s\nModel: %s (%s)\nURL: %s\n", $this->friendlyName, $this->deviceType, $this->ip, $this->manufacturer, $this->modelName, $this->modelDescription, $this->specUrl ); if (count($this->services)>0) { $services = " = ".join("\n = ",array_map("strval", $this->services)); $services = join("\n ", explode("\n", rtrim($services))); $info.= $services."\n"; } if (count($this->devices)>0) { $devices = " + ".join("\n + ",array_map("strval", $this->devices)); $devices = join("\n ", explode("\n", rtrim($devices))); $info.= $devices."\n"; } return $info; } }