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 #4 from clarkstuth/master
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Aug 7, 2014
2 parents f26ef98 + d079e8d commit 2ecbdb0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Nmap/Nmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Nmap

private $disableReverseDNS = false;

private $treatHostsAsOnline = false;

/**
* @return Nmap
*/
Expand Down Expand Up @@ -86,6 +88,10 @@ public function scan(array $targets, array $ports = array())
$options[] = '-n';
}

if (true == $this->treatHostsAsOnline) {
$options[] = '-Pn';
}

$options[] = '-oX';
$command = sprintf('nmap %s %s %s',
implode(' ', $options),
Expand Down Expand Up @@ -162,6 +168,18 @@ public function disableReverseDNS($disable = true)
return $this;
}

/**
* @param boolean $disable
*
* @return Nmap
*/
public function treatHostsAsOnline($disable = true)
{
$this->treatHostsAsOnline = $disable;

return $this;
}

private function parseOutputFile($xmlFile)
{
$xml = simplexml_load_file($xmlFile);
Expand Down
16 changes: 16 additions & 0 deletions tests/Nmap/Tests/NmapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,20 @@ public function testScanWithoutReverseDNS()
->disableReverseDNS()
->scan(array('williamdurand.fr'));
}

public function testScanWithTreatHostsAsOnline()
{
$outputFile = __DIR__ . '/Fixtures/test_scan_with_verbose.xml';
$expectedCommand = sprintf("nmap -Pn -oX '%s' 'williamdurand.fr'", $outputFile);

$executor = $this->getMock('Nmap\Util\ProcessExecutor');
$executor
->expects($this->once())
->method('execute')
->with($this->equalTo($expectedCommand))
->will($this->returnValue(0));

$nmap = new Nmap($executor, $outputFile);
$hosts = $nmap->treatHostsAsOnline()->scan(array('williamdurand.fr'));
}
}

0 comments on commit 2ecbdb0

Please sign in to comment.