Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jas-
Last active December 23, 2017 23:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jas-/eae6b0c6e82a4e072b97 to your computer and use it in GitHub Desktop.
Save jas-/eae6b0c6e82a4e072b97 to your computer and use it in GitHub Desktop.
node.js libnmap example usage
/*!
* libnmap
* Copyright(c) 2013-2015 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap')
, opts = {
timeout: 900, // 900s = 10m and increases the reliability of scan results
flags: [
'-T0', // Paranoid scan type; very slow but accurate
'--max-retries 10', // Don't give up on slow responding hosts
'--ttl 200ms', // Accomodate for slow connections by setting the packets TTL value higher
'--scan-delay 10s', // Account for host 'rate limiting'
'--max-rate 30', // Slows down packet spewing to account for IDS protections
],
range: ['scanme.nmap.org', '172.17.190.0/24']
};
nmap.scan(opts, function(err, report) {
if (err) throw new Error(err);
for (var item in report) {
console.log(JSON.stringify(report[item], null, 2));
}
});
/*!
* node-libnmap
* Copyright(c) 2013-2015 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap')
, opts = {
// Use 4, 8, 16 or 32 for class A & B (default is 16)
// The larger the scan range the smaller the blocksize
// maximum is 128 which is adequate for class C networks.
blocksize: 8,
range: ['scanme.nmap.org', '192.168.0.0/17']
};
nmap.scan(opts, function(err, report) {
if (err) throw new Error(err);
for (var item in report) {
console.log(item);
console.log(JSON.stringify(report[item], null, 2));
}
});
/*!
* node-libnmap
* Copyright(c) 2013-2015 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap')
, opts = {
range: ['scanme.nmap.org', '172.17.190.0/24']
};
nmap.scan(opts, function(err, report) {
if (err) throw new Error(err);
for (var item in report) {
console.log(JSON.stringify(report[item], null, 2));
}
});
/*!
* node-libnmap
* Copyright(c) 2013-2015 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap');
nmap.discover(function(err, report) {
if (err) throw new Error(err);
for (var item in report) {
console.log(JSON.stringify(report[item], null, 2));
}
});
/*!
* node-libnmap
* Copyright(c) 2013-2015 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap')
, opts = {
flags: [
'-sV', // Open port to determine service (i.e. FTP, SSH etc)
'-O', // OS finger printing (requires elevated privileges)
'-sC' // Enables the nmap scripts (all) against each host (requires elevated privileges)
],
range: ['scanme.nmap.org', '192.168.0.0/26']
};
nmap.scan(opts, function(err, report) {
if (err) throw err;
for (var item in report) {
console.log(JSON.stringify(report[item], null, 2));
}
});
/*!
* libnmap
* Copyright(c) 2013-2016 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap')
, opts = {
range: [
'scanme.nmap.org',
'2001:db8::/128'
]
};
nmap.scan(opts, function(err, report) {
if (err) throw new Error(err);
for (var item in report) {
console.log(JSON.stringify(report[item], null, 2));
}
});
/*!
* node-libnmap
* Copyright(c) 2013-2015 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap')
, opts = {
// Scan IANA reserved, registered & some common network ports
ports: '1-1025,1433,1528,1776,3306,8443,8900-9020',
range: ['scanme.nmap.org', '192.168.0.0/26']
};
nmap.scan(opts, function(err, report) {
if (err) throw new Error(err);
for (var item in report) {
console.log(JSON.stringify(report[item], null, 2));
}
});
/*!
* node-libnmap
* Copyright(c) 2013-2015 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap')
, opts = {
threshold: 2048, // maximum of 2048 child processes (depending on range & blocksize)
range: ['scanme.nmap.org', '192.168.0.0/26']
};
nmap.scan(opts, function(err, report) {
if (err) throw new Error(err);
for (var item in report) {
console.log(JSON.stringify(report[item], null, 2));
}
});
/*!
* node-libnmap
* Copyright(c) 2013-2015 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap')
, opts = {
udp: true, // requires root privileges
range: ['scanme.nmap.org', '192.168.0.0/26']
};
nmap.scan(opts, function(err, report) {
if (err) throw new Error(err);
for (var item in report) {
console.log(JSON.stringify(report[item], null, 2));
}
});
/*!
* node-libnmap
* Copyright(c) 2013-2015 Jason Gerfen <jason.gerfen@gmail.com>
* License: MIT
*/
var nmap = require('libnmap')
, opts = {
json: false,
range: ['scanme.nmap.org', '192.168.0.0/26']
};
nmap.scan(opts, function(err, report) {
if (err) throw new Error(err);
for (var item in report) {
console.log(report[item]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment