Build & leverage nmap as a node.js module, no need to install an nmap binary.
To install npm install libnmap
The install gets the nmap and OpenSSL sources and compiles them. See build tools for details.
Some package managers (pnpm, yarn, bun, and npm with ignore-scripts) do not
run install scripts unless you allow them. If a scan gives the error "the nmap
module is not compiled", allow the install script of libnmap and run
npm rebuild libnmap.
Example package requirements.
Debian, Ubuntu (apt)
sudo apt-get install build-essential perl python3 nodejs npm
Fedora, RHEL, CentOS, Rocky, AlmaLinux (dnf)
sudo dnf install gcc gcc-c++ make perl python3 diffutils tar nodejs npm
openSUSE (zypper)
sudo zypper install gcc gcc-c++ make perl python3 nodejs npm
Arch Linux, Manjaro (pacman)
sudo pacman -S --needed base-devel perl python nodejs npm
Gentoo (emerge)
sudo emerge --ask dev-lang/perl dev-lang/python net-libs/nodejs
The compiler and make are part of the base system.
Alpine (apk)
sudo apk add build-base linux-headers perl python3 nodejs npm
macOS
xcode-select --install brew install node
The Xcode command line tools supply the compiler, make, perl and python3.
scanScans the ports of each host in the rangediscoverFinds the neighbors on the IPv4 network of each network interface
range{Array} Hostnames, IPv4/IPv6 addresses, CIDR or address rangesports{String} Ports to scan (default1-1024)timeout{Number} Number of seconds to wait for each host (default120)flags{Array} More nmap flags (default-T4)udp{Boolean} Scan UDP ports (requires root)json{Boolean} JSON object as output (default), false produces XML
More examples are in the examples/ folder.
const nmap = require('libnmap'); const opts = { range: [ 'scanme.nmap.org', '10.0.2.0/25', '192.168.10.80-120', 'fe80::42:acff:fe11:fd4e/64' ], ports: '22,80,443' }; nmap.scan(opts, function(err, report) { if (err) throw err; console.log(JSON.stringify(report, null, 2)); });
const nmap = require('libnmap'); nmap.discover(function(err, report) { if (err) throw err; console.log(JSON.stringify(report, null, 2)); });
To test npm test
This software is licensed under the Nmap Public Source License, the same license as nmap. See LICENSE.
Copyright Jason Gerfen, 2013.


