Build & leverage zmap as a node.js module, no need to install a zmap binary.
To install npm install libzmap
Example package requirements. The last line of each list is only necessary for an install from git.
Debian, Ubuntu (apt)
sudo apt-get install build-essential python3 pkg-config \
libpcap-dev libjson-c-dev libgmp-dev libjudy-dev libunistring-dev \
gengetopt flex byaccUbuntu 24.04 and Debian 12 package node.js 18; install node.js 22 or later from nodejs.org.
Fedora, RHEL, CentOS, Rocky, AlmaLinux (dnf)
sudo dnf install gcc gcc-c++ make python3 tar nodejs npm \
libpcap-devel json-c-devel gmp-devel Judy-devel libunistring-devel \
gengetopt flex byaccOn RHEL and its rebuilds, Judy-devel and gengetopt are in EPEL.
openSUSE (zypper)
sudo zypper install gcc gcc-c++ make python3 nodejs22 npm22 \
libpcap-devel libjson-c-devel gmp-devel judy-devel libunistring-devel \
gengetopt flex byaccArch Linux, Manjaro (pacman)
sudo pacman -S --needed base-devel python nodejs npm \
libpcap json-c gmp judy libunistring \
gengetopt flex byaccGentoo (emerge)
sudo emerge --ask net-libs/nodejs net-libs/libpcap dev-libs/json-c dev-libs/gmp \
dev-libs/judy dev-libs/libunistring \
dev-util/gengetopt sys-devel/flex dev-util/byaccAlpine (apk)
sudo apk add build-base linux-headers python3 pkgconf nodejs npm \
libpcap-dev json-c-dev gmp-dev judy-dev libunistring-dev \
gengetopt flex byaccmacOS
xcode-select --install
brew install node json-c gmp judy libunistring pkgconf \
gengetopt byaccThe Xcode command line tools supply the compiler, make, python3 and flex. macOS includes libpcap.
zmap sends raw packets, so a scan needs root (sudo node script.js). On Linux
you can instead give node.js the capabilities one time:
sudo setcap cap_net_raw,cap_net_admin+ep "$(readlink -f "$(command -v node)")"zmapRuns a scan,zmap(opts, callback)scanRuns a scan and returns it:.done(promise), events,for awaitand.stop()isRunningTrue while a scan runs (one scan at a time in a process)
range{String|Array} Addresses or CIDR blocks to scanports{String} Ports to scan; without ports the scan is ICMP echoiface{String} Network interface (default: the interface of the default route)ipaddr{String} Source address(es), e.g.10.0.2.15-10.0.2.18mac{String} Gateway MAC addresswhitelist{String} File of networks to scanblacklist{String} File of networks to skipshards{Number} Withshardtotal, this scan is shard N of M (needsseed)seed{Number} Seed of the address order, the same on each shardthreads{Number} Send threadsrate{Number} Packets per second (default10000)probeModule{String}icmp_echoscan,tcp_synscan,udp,dns, ...dryrun{Boolean} Send no packets (needs no root)
Any other zmap option works in camelCase, e.g. maxRuntime, cooldownTime, outputFilter.
More examples are in the examples/ folder.
const zmap = require('libzmap');
const opts = {
iface: 'eth0',
ipaddr: '10.0.2.15-10.0.2.18',
mac: '52:54:00:12:34:56',
shards: 2,
shardtotal: 4,
seed: 1234,
threads: 10,
range: '10.0.2.0/24',
blacklist: '/path/to/blacklist.conf',
whitelist: '/path/to/whitelist.conf'
};
zmap.zmap(opts, function(err, report) {
if (err) throw err;
console.log(JSON.stringify(report, null, 2));
});The report has hosts (each address that answered, with its ports), results
(each answer, with zmap's fields) and metadata (zmap's scan settings and statistics).
Each result as it arrives:
for await (const result of zmap.scan(opts)) {
console.log(JSON.stringify(result));
}To test npm test
This software is licensed under the Apache License 2.0, the same license as zmap.
Copyright Jason Gerfen, 2014.

