diff --git a/src/Nmap/Nmap.php b/src/Nmap/Nmap.php index c804a17..8a4bf56 100644 --- a/src/Nmap/Nmap.php +++ b/src/Nmap/Nmap.php @@ -231,7 +231,9 @@ private function parsePorts(\SimpleXMLElement $xmlPorts) (string) $port->attributes()->protocol, (string) $port->state->attributes()->state, new Service( - (string) $port->service->attributes()->name + (string) $port->service->attributes()->name, + (string) $port->service->attributes()->product, + (string) $port->service->attributes()->version ) ); } diff --git a/src/Nmap/Service.php b/src/Nmap/Service.php index f4d300c..4b2a238 100644 --- a/src/Nmap/Service.php +++ b/src/Nmap/Service.php @@ -17,13 +17,29 @@ class Service { private $name; - public function __construct($name) + private $product; + + private $version; + + public function __construct($name, $product, $version) { $this->name = $name; + $this->product = $product; + $this->version = $version; } public function getName() { return $this->name; } + + public function getProduct() + { + return $this->product; + } + + public function getVersion() + { + return $this->version; + } } diff --git a/tests/Nmap/Tests/NmapTest.php b/tests/Nmap/Tests/NmapTest.php index f4ea5d5..ee24b3f 100644 --- a/tests/Nmap/Tests/NmapTest.php +++ b/tests/Nmap/Tests/NmapTest.php @@ -121,6 +121,18 @@ public function testScanWithServiceInfo() $hosts = $nmap ->enableServiceInfo() ->scan(array('williamdurand.fr')); + + $host = current($hosts); + $ports = $host->getPorts(); + + $service = $ports[0]->getService(); + $this->assertEquals('ssh', $service->getName()); + $this->assertEquals('OpenSSH', $service->getProduct()); + $this->assertEquals('5.1p1 Debian 5github8', $service->getVersion()); + + $service = $ports[1]->getService(); + $this->assertEquals('http', $service->getName()); + $this->assertEquals('nginx', $service->getProduct()); } public function testScanWithVerbose()