Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Nmap/Nmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Nmap

private $treatHostsAsOnline = false;

private $enableArpPing = false;

private $executable;

private $timeout = 60;
Expand Down Expand Up @@ -106,6 +108,10 @@ public function scan(array $targets, array $ports = array())
$options[] = '-Pn';
}

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

$options[] = '-oX';
$command = sprintf('%s %s %s %s',
$this->executable,
Expand Down Expand Up @@ -159,6 +165,18 @@ public function enableVerbose($enable = true)
return $this;
}

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

return $this;
}

/**
* @param boolean $disable
*
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 @@ -222,6 +222,22 @@ public function testScanWithTreatHostsAsOnline()
$hosts = $nmap->treatHostsAsOnline()->scan(array('williamdurand.fr'));
}

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

$executor = $this->getProcessExecutorMock();
$executor
->expects($this->at(1))
->method('execute')
->with($this->equalTo($expectedCommand))
->will($this->returnValue(0));

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

public function testScanWithDefaultTimeout()
{
$outputFile = __DIR__ . '/Fixtures/test_scan.xml';
Expand Down