Skip to content
This repository has been archived by the owner on Jan 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10 from arall/master
Browse files Browse the repository at this point in the history
Service info: Product & version
  • Loading branch information
willdurand committed Mar 24, 2015
2 parents e248a59 + a01113e commit 513fc34
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Nmap/Nmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}
Expand Down
18 changes: 17 additions & 1 deletion src/Nmap/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
12 changes: 12 additions & 0 deletions tests/Nmap/Tests/NmapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 513fc34

Please sign in to comment.