Skip to content

Commit acc7369

Browse files
authored
Merge pull request #10 from peter17/patch-5
Fix XML parsing when host is down, see #10 for further details.
2 parents 12cdce7 + c4aedbe commit acc7369

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/Nmap/XmlOutputParser.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,15 @@ public function parse(): array
168168
{
169169
$xml = simplexml_load_file($this->xmlFile);
170170

171-
if (!$xml instanceof SimpleXMLElement || !isset($xml->host)) {
171+
if (!$xml instanceof SimpleXMLElement || !isset($xml->runstats->hosts)) {
172+
throw new \InvalidArgumentException("{$this->xmlFile} does not appear to be valid.");
173+
}
174+
175+
if ((string) $xml->runstats->hosts->attributes()->up === '0') {
176+
return [];
177+
}
178+
179+
if (!isset($xml->host)) {
172180
throw new \InvalidArgumentException("{$this->xmlFile} does not appear to be valid.");
173181
}
174182

0 commit comments

Comments
 (0)