diff --git a/src/Nmap/Nmap.php b/src/Nmap/Nmap.php index 403ba3b..257605c 100644 --- a/src/Nmap/Nmap.php +++ b/src/Nmap/Nmap.php @@ -31,6 +31,8 @@ class Nmap private $disablePortScan = false; + private $disableReverseDNS = false; + /** * @return Nmap */ @@ -80,6 +82,10 @@ public function scan(array $targets, array $ports = array()) $options[] = '-p '.implode(',', $ports); } + if (true === $this->disableReverseDNS) { + $options[] = '-n'; + } + $options[] = '-oX'; $command = sprintf('nmap %s %s %s', implode(' ', $options), @@ -144,6 +150,18 @@ public function disablePortScan($disable = true) return $this; } + /** + * @param boolean $disable + * + * @return Nmap + */ + public function disableReverseDNS($disable = true) + { + $this->disableReverseDNS = $disable; + + return $this; + } + private function parseOutputFile($xmlFile) { $xml = simplexml_load_file($xmlFile); diff --git a/tests/Nmap/Tests/Fixtures/test_ping_without_reverse_dns.xml b/tests/Nmap/Tests/Fixtures/test_ping_without_reverse_dns.xml new file mode 100644 index 0000000..98d5370 --- /dev/null +++ b/tests/Nmap/Tests/Fixtures/test_ping_without_reverse_dns.xml @@ -0,0 +1,25 @@ + + + + + + + + +
+ + + + + + + + + + + + + + + + diff --git a/tests/Nmap/Tests/NmapTest.php b/tests/Nmap/Tests/NmapTest.php index 6854148..504f3c5 100644 --- a/tests/Nmap/Tests/NmapTest.php +++ b/tests/Nmap/Tests/NmapTest.php @@ -158,4 +158,22 @@ public function testPingScan() ->disablePortScan() ->scan(array('williamdurand.fr')); } + + public function testScanWithoutReverseDNS() + { + $outputFile = __DIR__ . '/Fixtures/test_ping_without_reverse_dns.xml'; + $expectedCommand = sprintf("nmap -n -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 + ->disableReverseDNS() + ->scan(array('williamdurand.fr')); + } }