nmap is a PHP wrapper for Nmap, a free security scanner for network exploration. This is (mostly) a fork of willdurand/nmap with PHP 7 and vimeo/psalm static analysis improvements.

Maintainers

Details

github.com/DavidGoodwin/nmap

Source

Installs: 1 097

Dependents: 0

Suggesters: 0

Security: 0

Stars: 12

Watchers: 2

Forks: 57

3.0.2 2023-12-04 15:02 UTC

This package is auto-updated.

Last update: 2024-05-04 15:48:13 UTC


README

This project is maintained fork of the original project: https://github.com/willdurand/nmap

Nmap

Nmap is a PHP wrapper for Nmap, a free security scanner for network exploration.

PHP Build

Starting a scan

$hosts = Nmap::create()->scan([ 'example.com' ]);

$ports = $hosts[0]->getOpenPorts();

You can specify the ports you want to scan:

$nmap = new Nmap();

$nmap->scan([ 'example.com' ], [ 21, 22, 80 ]);

OS detection and Service Info are disabled by default, if you want to enable them, use the enableOsDetection() and/or enableServiceInfo() methods:

$nmap
    ->enableOsDetection()
    ->scan([ 'example.com' ]);

$nmap
    ->enableServiceInfo()
    ->scan([ 'example.com' ]);

// Fluent interface!
$nmap
    ->enableOsDetection()
    ->enableServiceInfo()
    ->scan([ 'example.com' ]);

Turn the verbose mode by using the enableVerbose() method:

$nmap
    ->enableVerbose()
    ->scan([ 'example.com' ]);

For some reasons, you might want to disable port scan, that is why nmap provides a disablePortScan() method:

$nmap
    ->disablePortScan()
    ->scan([ 'example.com' ]);

You can also disable the reverse DNS resolution with disableReverseDNS():

$nmap
    ->disableReverseDNS()
    ->scan([ 'example.com' ]);

You can define the process timeout (default to 60 seconds) with setTimeout():

$nmap
    ->setTimeout(120)
    ->scan([ 'example.com' ]);

You can run specific scripts with setScripts() and get the result with getScripts():

$hosts = $nmap
    ->setTimeout(120)
    ->scan([ 'example.com' ], [ 443 ]);
    
$hosts[0]->setScripts(['ssl-heartbleed']);
$ports = $hosts[0]->getOpenPorts();

$ports[0]->getScripts();

Nmap XML output

Parse existing output:

Nmap::parseOutput($xmlFile);

or

$parser = new XmlOutputParser($xmlFile);
$parser->parse();

Validation output file using the Nmap DTD. A custom DTD path can be passed to the validate function.

$parser = new XmlOutputParser($xmlFile);
$parser->validate();

Installation

The recommended way to install nmap is through Composer:

For PHP 8.0 and above -

{
    "require": {
        "palepurple/nmap": "^3.0"
    }
}

For older versions of PHP, try ^2.0; see also https://github.com/DavidGoodwin/nmap/releases/tag/2.0.1

License

nmap is released under the MIT License. See the bundled LICENSE file for details.