arpscan-new
Advanced tools
Comparing version 1.3.9 to 1.4.0
@@ -6,12 +6,5 @@ /** | ||
var extend = require('gextend'); | ||
var spawn = require('child_process').spawn; | ||
var suspawn = require('suspawn'); | ||
var async = require('async'); | ||
var os = require('os'); | ||
var interfaces = os.networkInterfaces(); | ||
var fs = require('fs'); | ||
var console = new (require('my-console')).Console(); | ||
interfaces = Object.keys(interfaces); | ||
var DEFAULTS = { | ||
@@ -26,120 +19,26 @@ command: 'arp-scan', | ||
var scan = function (cb, options) { | ||
var buffer = '', | ||
out = [], | ||
errbuf = '', | ||
arp = {}; | ||
options.args = options.args.concat(['--ignoredups', '-interface', options.interface]); | ||
var cmd = options.command + ' ' + options.args.join(' '); | ||
if (options.verbose) { | ||
console.log(options.sudo ? 'sudo ' : '' + cmd); | ||
} | ||
// console.info(options.command, options.args); | ||
if (options.sudo) { | ||
arp = suspawn(options.command, options.args); | ||
} else { | ||
arp = spawn(options.command, options.args); | ||
} | ||
if (arp && arp.stdout) { | ||
arp.stdout.on('data', function onData (data) { | ||
buffer += data; | ||
}); | ||
arp.stderr.on('data', function onError (data) { | ||
errbuf += data; | ||
}); | ||
arp.on('close', function onClose (code) { | ||
if (code !== 0) return cb(code, null); | ||
buffer = buffer.split('\n'); | ||
buffer = buffer.slice(2, -4); | ||
buffer.forEach(function lineParser (line) { | ||
var chunks = line.split('\t'); | ||
out.push({ | ||
ip: chunks[0], | ||
mac: (chunks[1] || '').toUpperCase(), | ||
vendor: chunks[2], | ||
//interfaces: interfaces, | ||
timestamp: Date.now() | ||
}); | ||
var out = []; | ||
fs.readFile('/proc/net/arp', function (err, data) { | ||
if (err) { | ||
console.error(err); | ||
cb(err, null); | ||
} else { | ||
data = data.toString().trim().split('\n'); | ||
data.splice(0, 1); | ||
data.forEach(function (line) { | ||
const chunks = line.trim().replace(/\s\s+/g, ' ').split(' '); | ||
if (Number(chunks[2]).toString(10) == 2) { | ||
out.push({ | ||
ip: chunks[0], | ||
mac: chunks[3].toString().toUpperCase(), | ||
interface: chunks[5], | ||
timestamp: Date.now() | ||
}); | ||
} | ||
}); | ||
cb(null, out); | ||
}); | ||
arp.on('error', function (err) { | ||
cb(err, null); | ||
}); | ||
arp.on('exit', function (code, signal) { | ||
}); | ||
} else { | ||
cb(true, null); | ||
} | ||
} | ||
}); | ||
}; | ||
function scanner (callback, options) { | ||
var list = []; | ||
if (options !== undefined && (options.interface !== undefined && options.interface !== '')) { | ||
options = extend({}, DEFAULTS, options); | ||
scan(function (err, data) { | ||
if (err) { | ||
// console.log('Error in ' + options.interface + ' interface. Error code is ' + err); | ||
} else { | ||
if (options.listByInterface) { | ||
var result = {}; | ||
result[options.interface] = data; | ||
list.push(result); | ||
} else { | ||
if (data && data.length) { | ||
for (var kk = 0; kk < data.length; kk++) { | ||
list.push(data[kk]); | ||
} | ||
} | ||
} | ||
} | ||
callback(err, list) | ||
}, options); | ||
} else { | ||
options = extend({}, DEFAULTS, options); | ||
async.eachSeries(interfaces, function (inter, cbl) { | ||
if (inter !== 'lo') { | ||
options.args = ['-l']; | ||
options.interface = inter; | ||
scan(function (err, data) { | ||
if (err) { | ||
// console.log('Error in ' + options.interface + ' interface. Error code is ' + err); | ||
} else { | ||
if (options.listByInterface) { | ||
var result = {}; | ||
result[inter] = data; | ||
list.push(result); | ||
} else { | ||
if (data && data.length) { | ||
for (var kk = 0; kk < data.length; kk++) { | ||
list.push(data[kk]); | ||
} | ||
} | ||
} | ||
} | ||
cbl(); | ||
}, options); | ||
} else { | ||
cbl(); | ||
} | ||
}, function (err) { | ||
callback(err, list) | ||
}); | ||
} | ||
} | ||
module.exports = scanner; | ||
module.exports.promisify = function () { | ||
return require('./arpscanner-promise') | ||
}; | ||
// exports.DEFAULTS = DEFAULTS; | ||
module.exports = scan; |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "1.3.9", | ||
"version": "1.4.0", | ||
"license": "MIT", | ||
@@ -14,0 +14,0 @@ "author": "Terzetto Infotech <info@terzettoinfotech.com> (http://terzettoinforech.com)", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
17258
11
222
1
2