From 9970f30bb240327c4075bdb423a038ec70a56492 Mon Sep 17 00:00:00 2001 From: Daniel Cabanaw Date: Mon, 29 Jan 2018 11:59:33 -0500 Subject: [PATCH] Add ARP ping option Add ability to enable ARP ping --- src/Nmap/Nmap.php | 18 ++++++++++++++++++ tests/Nmap/Tests/NmapTest.php | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Nmap/Nmap.php b/src/Nmap/Nmap.php index 7a84bc0..fe538c1 100644 --- a/src/Nmap/Nmap.php +++ b/src/Nmap/Nmap.php @@ -35,6 +35,8 @@ class Nmap private $treatHostsAsOnline = false; + private $enableArpPing = false; + private $executable; private $timeout = 60; @@ -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, @@ -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 * diff --git a/tests/Nmap/Tests/NmapTest.php b/tests/Nmap/Tests/NmapTest.php index 337bf43..e419872 100644 --- a/tests/Nmap/Tests/NmapTest.php +++ b/tests/Nmap/Tests/NmapTest.php @@ -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';