From a01113eb9bbee24a9d563da57560577c59932b5b Mon Sep 17 00:00:00 2001 From: arall Date: Tue, 24 Mar 2015 18:48:26 +0100 Subject: [PATCH] Service info: Product & version --- src/Nmap/Nmap.php | 4 +++- src/Nmap/Service.php | 18 +++++++++++++++++- tests/Nmap/Tests/NmapTest.php | 12 ++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) 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()