Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/no-defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*!
* libnmap
* Copyright(c) 2021 Evandro Brandão <evandroaribel@gmail.com>
* License: MIT
*/

'use strict'

const nmap = require('../');
const opts = {
range: ['scanme.nmap.org', '127.0.0.1'],
noDefaults: true
};


nmap.scan(opts, function(err, report) {
if (err) throw new Error(err);

for (let item in report) {
console.log(JSON.stringify(report[item], null, 2));
}
});
14 changes: 9 additions & 5 deletions lib/classes/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ class tools extends emitter {
*/
command(opts, block) {
const flags = opts.flags.join(' ');
const proto = (opts.udp) ? ' -sU' : ' ';
const to = `--host-timeout=${opts.timeout}s `;
const proto = (opts.udp) ? ' -sU ' : ' ';
const to = opts.timeout ? `--host-timeout=${opts.timeout}s ` :'';
const ipv6 = (validation.test(validation.patterns.IPv6, block)) ?
' -6 ' : ' ';

return (opts.ports) ?
`${opts.nmap+proto} ${to}${flags}${ipv6}-p${opts.ports} ${block}` :
`${opts.nmap+proto} ${to}${flags}${ipv6}${block}`;
`${opts.nmap+proto}${to}${flags}${ipv6}-p${opts.ports} ${block}` :
`${opts.nmap+proto}${to}${flags}${ipv6}${block}`;
}


Expand Down Expand Up @@ -197,6 +196,11 @@ class tools extends emitter {
const ranges = [];
const called = caller.get()[1].getFunctionName();

/** Remove defaults options if user disabled it (flags, ports, timeout) */
if(opts.noDefaults) {
const {ports, timeout, ...defaultsRest} = defaults;
defaults = {...defaultsRest, flags: []};
}
/* Override 'defaults.flags' array with 'opts.flags' (prevents merge) */
if (/array/.test(typeof opts.flags))
defaults.flags = opts.flags;
Expand Down
1 change: 0 additions & 1 deletion lib/classes/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class validation {
const scope = this;
let errors = [];
let result;

scope.exists(opts.nmap, (result) => {
if (!result) {

Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "libnmap",
"name": "libnmap-xtr",
"version": "v0.4.19",
"description": "libnmap for node.js",
"author": "Jason Gerfen <jason.gerfen@gmail.com>",
"author": "Jason Gerfen <jason.gerfen@gmail.com>, Evandro Brandão <evandroaribel@gmail.com>",
"keywords": [
"nmap",
"libnmap",
Expand All @@ -23,14 +23,11 @@
],
"repository": {
"type": "git",
"url": "https://github.com/jas-/node-libnmap.git"
},
"bugs": {
"url": "https://github.com/jas-/node-libnmap/issues"
"url": "https://github.com/kingaribel/node-libnmap.git"
},
"scripts": {
"start": "node index.js",
"test": "./node_modules/.bin/mocha -R spec"
"test": "./node_modules/.bin/mocha "
},
"dependencies": {
"async": "^2.6.3",
Expand Down
50 changes: 50 additions & 0 deletions test/no-defaults.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*!
* libnmap
* Copyright(c) 2013-2019 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/

'use strict'

const nmap = require('../');
const timeout = 1024 * 1024 * 3;
const chai = require('chai');
const should = chai.should();
const expect = chai.expect;
const opts = {
range: [
'127.0.0.1',
'scanme.nmap.org',
'::1'
],
noDefaults: true
};


describe('scan method', function () {

context('reporting', function () {
it('json', function (done) {
this.timeout(timeout);

nmap.scan(opts, function (err, report) {
should.not.exist(err);

report.should.be.a('object');
done();
});
});

it('xml', function (done) {
this.timeout(timeout);
opts.json = false;

nmap.scan(opts, function (err, report) {
should.not.exist(err);

report.should.be.a('object');
done();
});
});
});
});