NetMap
A wrapper for programmatically accessing the command line tool Nmap. You must have Nmap installed on your device, but as long as it is, anything described below will work.
How to Use
The import exposes the classes Subnet
and Host
. Every method that yields data returns a Promise.
Subnet
This is for scanning all IPs in a subnet.
Interface
-
constructor(addr[, options = {bits = 24, outputFile = null}])
-
setIP(addr)
: Sets the start IP address of the range. This method is recommended for setting this property, as it will verify that the new address is in a valid IPv4 format. -
setBits(bits)
: Sets the number of bits for the IP range. This method is recommended for setting this property, as it will verify that the new value is valid. -
getHosts([options = {outputFile = null}])
: Finds all hosts in the subnet without checking any ports. -
scanForPorts(ports[, options = {outputFile = null, version = false, udp = false}])
: Scans all "up" hosts in the subnet and returns the hosts' status for the input ports. Theports
argument can be a single port or an array. TheoutputFile
option may be used to specify an override output file to use instead of the output file specified in the constructor. If no output file is specified in either the constructor OR this method, the data will not be written to any file. Theversion
option will attempt to perform version detection, and theudp
option will attempt to form UDP connections. -
scanForOpenPorts(ports[, options = {outputFile = null, all = false, version = false, udp = false}])
: Scans all "up" hosts in the subnet and returns only the hosts with the input ports open. Theports
argument can be a single port or an array. If theall
option is set totrue
, only the hosts with all the input ports open will be returned.
Data Format
The general format for the responses from the scanForPorts
and scanForOpenPorts
methods is
For getHosts
, the format is
Example
const Subnet = ; const subnet = '192.168.86.0' outputFile: './data.json' ; subnet // `nmap -sV 192.168.86.0/24 -p 515,9100 -oG - | grep -e open` ;
Host
This is for scanning a single host.
Interface
-
constructor(addr[options = {outputFile = null}])
-
scan([options = {outputFile = null, version = false, udp = false, flags = []}])
: Returns open ports on the host in the same format as theports
property of a single host from the subnet scans. Theflags
option is an array of flags to be appended onto the Nmap call, each separated by a space. -
scanCommon([options = {outputFile = null, flags = []}])
: Checks the 100 most common ports and returns open ports on the host in the same format as theports
property of a single host from the subnet scans. -
scanPorts(ports[, options = {outputFile = null, version = false, udp = false, flags = []}])
: Returns port data for each input port. Theports
argument can be a single port or an array.
Example
const Host = ; const host = '192.168.86.54'; host // `nmap -sT 192.168.86.54 -p 515,9100` ;