libnmap 0.4.19 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,20 +1,17 @@
1
- The MIT License (MIT)
1
+ libnmap
2
+ Copyright (c) 2013 Jason Gerfen
2
3
 
3
- Copyright (c) 2013 - 2019 Jason Gerfen <jason.gerfen@gmail.com>
4
+ nmap
5
+ Copyright (c) 1996 - 2026 Nmap Software LLC
4
6
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
7
+ You can use, redistribute, and/or modify
8
+ this code under the terms of the Nmap Public Source License
9
+ version 0.95.
11
10
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ Nmap Public Source License for more details.
14
15
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ The full text of the Nmap Public Source License is in the nmap
17
+ sources (src/nmap/LICENSE) and at <https://nmap.org/npsl/>.
package/README.md CHANGED
@@ -1,47 +1,105 @@
1
- # libnmap
1
+ # libnmap
2
2
 
3
- API to access nmap from node.js
4
-
5
- [![npm](https://img.shields.io/npm/v/libnmap.svg)](https://npmjs.com/package/libnmap) [![Build Status](https://travis-ci.org/jas-/node-libnmap.png?branch=master)](https://travis-ci.org/jas-/node-libnmap) [![Dependencies](https://img.shields.io/david/jas-/node-libnmap.svg)](https://david-dm.org/jas-/node-libnmap) ![Downloads](https://img.shields.io/npm/dm/libnmap.svg) [![Known Vulnerabilities](https://snyk.io/test/github/jas-/node-libnmap/badge.svg?targetFile=package.json)](https://snyk.io/test/github/jas-/node-libnmap?targetFile=package.json)
3
+ Build & leverage [nmap](https://github.com/nmap/nmap) as a node.js module, no need to install an `nmap` binary.
6
4
 
5
+ [![npm](https://img.shields.io/npm/v/libnmap.svg)](https://npmjs.com/package/libnmap) [![CI](https://github.com/jas-/node-libnmap/actions/workflows/ci.yml/badge.svg)](https://github.com/jas-/node-libnmap/actions/workflows/ci.yml) ![Downloads](https://img.shields.io/npm/dm/libnmap.svg) [![Known Vulnerabilities](https://snyk.io/test/github/jas-/node-libnmap/badge.svg?targetFile=package.json)](https://snyk.io/test/github/jas-/node-libnmap?targetFile=package.json)
7
6
 
8
7
  ## install ##
9
8
 
10
9
  To install `npm install libnmap`
11
10
 
12
- ## methods ##
11
+ The install gets the nmap and OpenSSL sources and compiles them. See `build tools` for details.
13
12
 
14
- * `scan` Performs scan given available range & optional port
15
- * `discover` Retrieves list of online network neighbors
13
+ Some package managers (pnpm, yarn, bun, and npm with `ignore-scripts`) do not
14
+ run install scripts unless you allow them. If a scan gives the error "the nmap
15
+ module is not compiled", allow the install script of `libnmap` and run
16
+ `npm rebuild libnmap`.
16
17
 
17
- ## options ##
18
+ ### build tools ###
18
19
 
19
- * `nmap` {String} Path to NMAP binary
20
- * `verbose` {Boolean} Turn on verbosity during scan(s)
21
- * `ports` {String} Range of ports to scan
22
- * `range` {Array} An array of hostnames/ipv4/ipv6, CIDR or ranges
23
- * `timeout` {Number} Number of seconds to wait for host/port response
24
- * `blocksize` {Number} Number of hosts per network scanning block
25
- * `threshold` {Number} Max number of spawned process
26
- * `flags` {Array} Array of flags for .spawn()
27
- * `udp` {Boolean} UDP scan mode enabled
28
- * `json` {Boolean} JSON object as output, false produces XML
20
+ Example package requirements.
29
21
 
30
- ## tests ##
22
+ <details>
23
+ <summary>Debian, Ubuntu (apt)</summary>
31
24
 
32
- To test `npm test`
25
+ ```sh
26
+ sudo apt-get install build-essential perl python3 nodejs npm
27
+ ```
28
+ </details>
29
+
30
+ <details>
31
+ <summary>Fedora, RHEL, CentOS, Rocky, AlmaLinux (dnf)</summary>
32
+
33
+ ```sh
34
+ sudo dnf install gcc gcc-c++ make perl python3 diffutils tar nodejs npm
35
+ ```
36
+ </details>
37
+
38
+ <details>
39
+ <summary>openSUSE (zypper)</summary>
40
+
41
+ ```sh
42
+ sudo zypper install gcc gcc-c++ make perl python3 nodejs npm
43
+ ```
44
+ </details>
45
+
46
+ <details>
47
+ <summary>Arch Linux, Manjaro (pacman)</summary>
48
+
49
+ ```sh
50
+ sudo pacman -S --needed base-devel perl python nodejs npm
51
+ ```
52
+ </details>
53
+
54
+ <details>
55
+ <summary>Gentoo (emerge)</summary>
56
+
57
+ ```sh
58
+ sudo emerge --ask dev-lang/perl dev-lang/python net-libs/nodejs
59
+ ```
60
+
61
+ The compiler and `make` are part of the base system.
62
+ </details>
63
+
64
+ <details>
65
+ <summary>Alpine (apk)</summary>
66
+
67
+ ```sh
68
+ sudo apk add build-base linux-headers perl python3 nodejs npm
69
+ ```
70
+ </details>
71
+
72
+ <details>
73
+ <summary>macOS</summary>
74
+
75
+ ```sh
76
+ xcode-select --install
77
+ brew install node
78
+ ```
79
+
80
+ The Xcode command line tools supply the compiler, `make`, `perl` and `python3`.
81
+ </details>
82
+
83
+ ## methods ##
84
+
85
+ * `scan` Scans the ports of each host in the range
86
+ * `discover` Finds the neighbors on the IPv4 network of each network interface
87
+
88
+ ## options ##
89
+
90
+ * `range` {Array} Hostnames, IPv4/IPv6 addresses, CIDR or address ranges
91
+ * `ports` {String} Ports to scan (default `1-1024`)
92
+ * `timeout` {Number} Number of seconds to wait for each host (default `120`)
93
+ * `flags` {Array} More nmap flags (default `-T4`)
94
+ * `udp` {Boolean} Scan UDP ports (requires root)
95
+ * `json` {Boolean} JSON object as output (default), false produces XML
33
96
 
34
97
  ## examples ##
35
98
 
36
- A default usage example. For more advanced and possible options please
37
- see [here](https://github.com/jas-/node-libnmap/tree/master/examples) or simply
38
- look in the included `examples/` folder.
99
+ More examples are in the `examples/` folder.
39
100
 
40
101
  ### scan ###
41
102
 
42
- The example show shows the types of host ranges supported. In this example the
43
- default IANA range of reserved ports is scanned per host in each range (1024).
44
-
45
103
  ```javascript
46
104
  const nmap = require('libnmap');
47
105
  const opts = {
@@ -50,46 +108,35 @@ const opts = {
50
108
  '10.0.2.0/25',
51
109
  '192.168.10.80-120',
52
110
  'fe80::42:acff:fe11:fd4e/64'
53
- ]
111
+ ],
112
+ ports: '22,80,443'
54
113
  };
55
114
 
56
115
  nmap.scan(opts, function(err, report) {
57
- if (err) throw new Error(err);
116
+ if (err) throw err;
58
117
 
59
- for (let item in report) {
60
- console.log(JSON.stringify(report[item]));
61
- }
118
+ console.log(JSON.stringify(report, null, 2));
62
119
  });
63
120
  ```
64
121
 
65
122
  ### discover ###
66
123
 
67
- The discover method requires nodejs < `v0.11.2` and can be used to aquire
68
- information about neighbors per network interface.
69
-
70
124
  ```javascript
71
125
  const nmap = require('libnmap');
72
126
 
73
127
  nmap.discover(function(err, report) {
74
- if (err) throw new Error(err);
128
+ if (err) throw err;
75
129
 
76
- for (let item in report) {
77
- console.log(JSON.stringify(report[item]));
78
- }
130
+ console.log(JSON.stringify(report, null, 2));
79
131
  });
80
132
  ```
81
133
 
82
- ### sample reports ###
83
-
84
- To see some output examples please take a look at the [json (default) & xml reports](https://gist.github.com/jas-/23e2a32110562388bef5).
85
-
86
- ## contributing ##
134
+ ## tests ##
87
135
 
88
- Contributions are welcome & appreciated. Refer to the [contributing document](https://github.com/jas-/node-libnmap/blob/master/CONTRIBUTING.md)
89
- to help facilitate pull requests.
136
+ To test `npm test`
90
137
 
91
138
  ## license ##
92
139
 
93
- This software is licensed under the [MIT License](https://github.com/jas-/node-libnmap/blob/master/LICENSE).
140
+ This software is licensed under the [Nmap Public Source License](https://nmap.org/npsl/), the same license as nmap. See [LICENSE](https://github.com/jas-/node-libnmap/blob/master/LICENSE).
94
141
 
95
- Copyright Jason Gerfen, 2013-2019.
142
+ Copyright Jason Gerfen, 2013.
package/binding.gyp ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "variables": {
3
+ "nmap_src": "src/nmap"
4
+ },
5
+ "target_defaults": {
6
+ "xcode_settings": { "MACOSX_DEPLOYMENT_TARGET": "11.0" }
7
+ },
8
+ "targets": [
9
+ {
10
+ "target_name": "nmap",
11
+ "sources": [ "src/addon.cc" ],
12
+ "include_dirs": [
13
+ "<(nmap_src)",
14
+ "<(nmap_src)/nbase",
15
+ "<(nmap_src)/nsock/include",
16
+ "<(nmap_src)/libdnet-stripped/include",
17
+ "<(nmap_src)/libpcap",
18
+ "<(nmap_src)/liblua",
19
+ "<(nmap_src)/liblinear",
20
+ "<(nmap_src)/libz",
21
+ "<(nmap_src)/libpcre/src"
22
+ ],
23
+ "defines": [ "HAVE_CONFIG_H" ],
24
+ # Unmodified upstream nmap: scripts/build-nmap.js compiles it and prints the link inputs.
25
+ "libraries": [ "<!@(node scripts/build-nmap.js)" ],
26
+ "cflags_cc": [ "-fvisibility=hidden", "-w" ],
27
+ "xcode_settings": {
28
+ "OTHER_CPLUSPLUSFLAGS": [ "-w" ],
29
+ "GCC_SYMBOLS_PRIVATE_EXTERN": "YES"
30
+ },
31
+ "conditions": [
32
+ # The module must use its own zlib and Lua, not the symbols that the node binary exports.
33
+ [ "OS=='linux'", {
34
+ "ldflags": [ "-Wl,-Bsymbolic", "-Wl,--exclude-libs,ALL" ]
35
+ }]
36
+ ]
37
+ }
38
+ ]
39
+ }
@@ -1,28 +1,32 @@
1
1
  /*!
2
2
  * libnmap
3
- * Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
4
- * License: MIT
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
5
  */
6
6
 
7
7
  'use strict'
8
8
 
9
+ // A slow scan for hosts that are far away, limit the rate of answers, or
10
+ // are behind an intrusion detection system. The scan of each port takes
11
+ // 10 seconds or more, so keep the list of ports and the range short.
12
+
9
13
  const nmap = require('../');
10
14
  const opts = {
11
- timeout: 900, // 900s = 15m and increases the reliability of scan results
15
+ timeout: 900, // 900s = 15m for each host
16
+ ports: '22,80,443',
12
17
  flags: [
13
- '-T0', // Paranoid scan type; very slow but accurate
18
+ '-T2', // Polite timing; slower than the default (-T4)
14
19
  '--max-retries 10', // Don't give up on slow responding hosts
15
- '--ttl 200ms', // Accomodate for slow connections by setting the packets TTL value higher
20
+ '--max-rtt-timeout 2s', // Wait longer for the answer on slow connections
16
21
  '--scan-delay 10s', // Account for host 'rate limiting'
17
- '--max-rate 30', // Slows down packet spewing to account for IDS protections
22
+ '--max-rate 30', // Send no more than 30 packets each second
18
23
  ],
19
- range: ['scanme.nmap.org', '172.17.0.0/24'],
24
+ range: ['scanme.nmap.org'],
20
25
  };
21
26
 
22
- nmap.scan(opts, function(err, report) {
23
- if (err) throw new Error(err);
24
27
 
25
- for (let item in report) {
26
- console.log(JSON.stringify(report[item], null, 2));
27
- }
28
+ nmap.scan(opts, (err, report) => {
29
+ if (err) throw err;
30
+
31
+ console.log(JSON.stringify(report, null, 2));
28
32
  });
@@ -1,22 +1,22 @@
1
1
  /*!
2
2
  * libnmap
3
- * Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
4
- * License: MIT
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
5
  */
6
6
 
7
7
  'use strict'
8
8
 
9
+ // The default scan: TCP ports 1-1024 of each host in the range.
10
+ // The range accepts hostnames, addresses, CIDR and address ranges.
11
+
9
12
  const nmap = require('../');
10
13
  const opts = {
11
- range: ['scanme.nmap.org', '192.168.0.0/26']
14
+ range: ['scanme.nmap.org']
12
15
  };
13
16
 
14
17
 
15
- nmap.scan(opts, function(err, report) {
18
+ nmap.scan(opts, (err, report) => {
16
19
  if (err) throw new Error(err);
17
20
 
18
- for (let item in report) {
19
- console.log(JSON.stringify(report[item], null, 2));
20
- }
21
+ console.log(JSON.stringify(report, null, 2));
21
22
  });
22
-
@@ -1,31 +1,23 @@
1
1
  /*!
2
2
  * libnmap
3
- * Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
4
- * License: MIT
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
5
  */
6
6
 
7
7
  'use strict'
8
8
 
9
- const nmap = require('../');
9
+ // Writes the report of one scan to a file.
10
+
10
11
  const fs = require('fs');
11
- const path = './scans/';
12
+ const nmap = require('../');
12
13
  const opts = {
13
- range: ['scanme.nmap.org', '172.17.190.0/26'],
14
+ range: ['scanme.nmap.org'],
14
15
  ports: '21,22,80,443'
15
16
  };
16
17
 
17
18
 
18
- nmap.scan(opts, function(err, report) {
19
- if (err) throw new Error(err);
20
-
21
- for (let item in report) {
22
- let data = JSON.stringify(report[item], null, 2),
23
- filename = item.replace(' ', '-');
24
-
25
- fs.writeFile(path+filename+'.json', data, function(error) {
26
- if (error) return console.log(error);
19
+ nmap.scan(opts, (err, report) => {
20
+ if (err) throw err;
27
21
 
28
- console.log('Wrote report for '+filename);
29
- });
30
- }
22
+ fs.writeFileSync('report.json', JSON.stringify(report, null, 2));
31
23
  });
@@ -1,17 +1,19 @@
1
1
  /*!
2
2
  * libnmap
3
- * Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
4
- * License: MIT
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
5
  */
6
6
 
7
7
  'use strict'
8
8
 
9
+ // Finds the neighbors on the IPv4 network of each network interface.
10
+ // As root, nmap uses ARP requests, which also give the MAC address.
11
+
9
12
  const nmap = require('../');
10
13
 
11
- nmap.discover({verbose: true}, function(err, report) {
12
- if (err) throw new Error(err);
13
14
 
14
- for (let item in report) {
15
- console.log(JSON.stringify(report[item], null, 2));
16
- }
17
- });
15
+ nmap.discover((err, report) => {
16
+ if (err) throw err;
17
+
18
+ console.log(JSON.stringify(report, null, 2));
19
+ });
@@ -0,0 +1,30 @@
1
+ /*!
2
+ * libnmap
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
+ */
6
+
7
+ 'use strict'
8
+
9
+ // Identifies the operating system of each host and the software behind
10
+ // each open port. OS detection requires root privileges, and is most
11
+ // accurate when the host has one open and one closed port.
12
+
13
+ const nmap = require('../');
14
+ const opts = {
15
+ timeout: 300,
16
+ flags: [
17
+ '-O', // OS detection from the TCP/IP stack of the host
18
+ '--osscan-guess', // Give the nearest matches if no match is exact
19
+ '-sV', // Software name and version of each open port
20
+ '--version-intensity 7' // 0 (fast) to 9 (try each probe); default is 7
21
+ ],
22
+ range: ['scanme.nmap.org']
23
+ };
24
+
25
+
26
+ nmap.scan(opts, (err, report) => {
27
+ if (err) throw err;
28
+
29
+ console.log(JSON.stringify(report, null, 2));
30
+ });
package/examples/flags.js CHANGED
@@ -1,28 +1,28 @@
1
1
  /*!
2
2
  * libnmap
3
- * Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
4
- * License: MIT
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
5
  */
6
6
 
7
7
  'use strict'
8
8
 
9
+ // More nmap flags for a scan. A flag can include its value.
10
+
9
11
  const nmap = require('../');
10
12
  const opts = {
11
13
  flags: [
12
14
  '-sV', // Open port to determine service (i.e. FTP, SSH etc)
13
15
  '-O', // OS finger printing (requires elevated privileges)
14
- '-sC', // Enables the nmap scripts (all) against each host (requires elevated privileges)
15
- '--traceroute', // Turns on tracerouting
16
+ '-sC', // Enables the default nmap scripts against each host
17
+ '--traceroute', // Turns on tracerouting (requires elevated privileges)
16
18
  '--script traceroute-geolocation' // Turns on GeoIP functionality per hops
17
19
  ],
18
- range: ['scanme.nmap.org', '172.17.0.0/24']
20
+ range: ['scanme.nmap.org']
19
21
  };
20
22
 
21
23
 
22
- nmap.scan(opts, function(err, report) {
24
+ nmap.scan(opts, (err, report) => {
23
25
  if (err) throw err;
24
26
 
25
- for (let item in report) {
26
- console.log(JSON.stringify(report[item], null, 2));
27
- }
28
- });
27
+ console.log(JSON.stringify(report, null, 2));
28
+ });
package/examples/ipv6.js CHANGED
@@ -1,21 +1,23 @@
1
1
  /*!
2
2
  * libnmap
3
- * Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
4
- * License: MIT
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
5
  */
6
6
 
7
7
  'use strict'
8
8
 
9
+ // Scans IPv4 and IPv6 hosts. nmap scans one address family for each run,
10
+ // so this range starts two runs at the same time. The one report has the
11
+ // hosts of the two runs.
12
+
9
13
  const nmap = require('../');
10
14
  const opts = {
11
15
  range: ['scanme.nmap.org', '2001:db8::/128']
12
16
  };
13
17
 
14
18
 
15
- nmap.scan(opts, function(err, report) {
16
- if (err) throw new Error(err);
19
+ nmap.scan(opts, (err, report) => {
20
+ if (err) throw err;
17
21
 
18
- for (let item in report) {
19
- console.log(JSON.stringify(report[item], null, 2));
20
- }
22
+ console.log(JSON.stringify(report, null, 2));
21
23
  });
package/examples/ports.js CHANGED
@@ -1,22 +1,23 @@
1
1
  /*!
2
2
  * libnmap
3
- * Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
4
- * License: MIT
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
5
  */
6
6
 
7
7
  'use strict'
8
8
 
9
+ // Scans a list of ports.
10
+ // Examples: '512' (single), '1-65535' (range), '10-30,80,443' (multiple)
11
+
9
12
  const nmap = require('../');
10
13
  const opts = {
11
- ports: '1-65535',
12
- range: ['scanme.nmap.org', '192.168.0.0/26']
14
+ ports: '21-25,80,443,8000-8100',
15
+ range: ['scanme.nmap.org']
13
16
  };
14
17
 
15
18
 
16
- nmap.scan(opts, function(err, report) {
17
- if (err) throw new Error(err);
19
+ nmap.scan(opts, (err, report) => {
20
+ if (err) throw err;
18
21
 
19
- for (let item in report) {
20
- console.log(JSON.stringify(report[item], null, 2));
21
- }
22
- });
22
+ console.log(JSON.stringify(report, null, 2));
23
+ });
@@ -0,0 +1,44 @@
1
+ /*!
2
+ * libnmap
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
+ */
6
+
7
+ 'use strict'
8
+
9
+ // Runs scripts of the Nmap Scripting Engine (NSE) against each host.
10
+ // nmap includes more than 600 scripts, in categories such as:
11
+ //
12
+ // default scripts that are fast, reliable and useful for most scans
13
+ // safe scripts that do not attack or put load on the host
14
+ // discovery scripts that find more data about the network
15
+ // vuln scripts that examine the host for known vulnerabilities
16
+ // auth scripts that examine authentication (anonymous access...)
17
+ // intrusive scripts that can stop a service or look like an attack
18
+ // brute, dos, exploit attacks; use only with written permission
19
+ //
20
+ // The --script value accepts script names, categories and expressions.
21
+ // This example selects the vulnerability and authentication scripts that
22
+ // are also in the safe category, with the default scripts.
23
+ //
24
+ // Only scan hosts that you own or have permission to scan.
25
+
26
+ const nmap = require('../');
27
+ const opts = {
28
+ timeout: 600,
29
+ ports: '21-25,53,80,110,143,443,445,3306,3389,5432,8080',
30
+ flags: [
31
+ '-sV', // Many scripts start only for a service that nmap identified
32
+
33
+ // The value is its own entry, so the spaces stay in one argument
34
+ '--script', 'default or ((vuln or auth) and safe)'
35
+ ],
36
+ range: ['scanme.nmap.org']
37
+ };
38
+
39
+
40
+ nmap.scan(opts, (err, report) => {
41
+ if (err) throw err;
42
+
43
+ console.log(JSON.stringify(report, null, 2));
44
+ });
@@ -1,22 +1,23 @@
1
1
  /*!
2
2
  * libnmap
3
- * Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
4
- * License: MIT
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
5
  */
6
6
 
7
7
  'use strict'
8
8
 
9
+ // The timeout is the number of seconds that nmap gives to each host
10
+ // (the nmap --host-timeout option). The default is 120 seconds.
11
+
9
12
  const nmap = require('../');
10
13
  const opts = {
11
14
  timeout: 900, // 900s = 15m and increases the reliability of scan results
12
- range: ['scanme.nmap.org', '192.168.0.0/26']
15
+ range: ['scanme.nmap.org']
13
16
  };
14
17
 
15
18
 
16
- nmap.scan(opts, function(err, report) {
17
- if (err) throw new Error(err);
19
+ nmap.scan(opts, (err, report) => {
20
+ if (err) throw err;
18
21
 
19
- for (let item in report) {
20
- console.log(JSON.stringify(report[item], null, 2));
21
- }
22
- });
22
+ console.log(JSON.stringify(report, null, 2));
23
+ });
package/examples/udp.js CHANGED
@@ -1,22 +1,24 @@
1
1
  /*!
2
2
  * libnmap
3
- * Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
4
- * License: MIT
3
+ * Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
4
+ * License: NPSL-0.95
5
5
  */
6
6
 
7
7
  'use strict'
8
8
 
9
+ // Scans UDP ports (the nmap -sU option). A UDP scan requires root
10
+ // privileges, and is slow: a closed port can limit the rate of the answers.
11
+
9
12
  const nmap = require('../');
10
13
  const opts = {
11
- udp: true, // requires root privileges
12
- range: ['scanme.nmap.org', '192.168.0.0/26']
14
+ udp: true,
15
+ ports: '53,67,123,161',
16
+ range: ['scanme.nmap.org']
13
17
  };
14
18
 
15
19
 
16
- nmap.scan(opts, function(err, report) {
17
- if (err) throw new Error(err);
20
+ nmap.scan(opts, (err, report) => {
21
+ if (err) throw err;
18
22
 
19
- for (let item in report) {
20
- console.log(JSON.stringify(report[item], null, 2));
21
- }
22
- });
23
+ console.log(JSON.stringify(report, null, 2));
24
+ });