lscanbot/src/scanner.js

56 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2018-09-24 21:21:53 +02:00
const arpScanner = require('arpscan/promise');
2020-05-13 00:59:15 +02:00
const appConfig = require('../config.json');
2018-09-24 21:21:53 +02:00
const db = require('./db');
function scanNetwork(userId) {
db.initScan(userId);
return (
arpScanner(appConfig.scanner)
2019-02-12 22:15:43 +01:00
.then(data => {
db.addDevices(userId, data)
return userId
})
.then(getDevicesNetwork)
.catch((err) => { return err})
2018-09-24 21:21:53 +02:00
);
}
function getDevicesNetwork(userId) {
return (db.getDevices(userId)
2019-02-12 22:15:43 +01:00
.then(data => {return data})
.catch(err => {return err})
2018-09-24 21:21:53 +02:00
);
}
function getInventoryNetwork() {
return (
db.getInventory()
2019-02-12 22:15:43 +01:00
.then(data => {return data})
.catch(err => {return err})
2018-09-24 21:21:53 +02:00
);
}
// wrapper DB
function initScannerDB() {
db.checkDB();
}
function addDeviceToTrack(data) {
const devArg = {
device: data[0],
owner: data[1],
2019-02-12 22:15:43 +01:00
mac: data[2].toUpperCase(),
2018-09-24 21:21:53 +02:00
};
db.addDeviceToInventory(devArg);
}
function removeDeviceToTrack(mac) {
db.removeDeviceFromInventory(mac);
}
module.exports.initScannerDB = initScannerDB;
module.exports.scanNetwork = scanNetwork;
module.exports.getInventoryNetwork = getInventoryNetwork;
module.exports.addDeviceToTrack = addDeviceToTrack;
module.exports.removeDeviceToTrack = removeDeviceToTrack;