mirror of
https://github.com/franjsco/lscanbot
synced 2025-02-17 20:10:43 +01:00
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
const arpScanner = require('arpscan/promise');
|
|
const appConfig = require('./config.json');
|
|
const db = require('./db');
|
|
|
|
function scanNetwork(userId) {
|
|
db.initScan(userId);
|
|
return (
|
|
arpScanner(appConfig.scanner)
|
|
.then(data => {
|
|
db.addDevices(userId, data)
|
|
return userId
|
|
})
|
|
.then(getDevicesNetwork)
|
|
.catch((err) => { return err})
|
|
);
|
|
}
|
|
|
|
function getDevicesNetwork(userId) {
|
|
return (db.getDevices(userId)
|
|
.then(data => {return data})
|
|
.catch(err => {return err})
|
|
);
|
|
}
|
|
|
|
function getInventoryNetwork() {
|
|
return (
|
|
db.getInventory()
|
|
.then(data => {return data})
|
|
.catch(err => {return err})
|
|
);
|
|
}
|
|
|
|
// wrapper DB
|
|
function initScannerDB() {
|
|
db.checkDB();
|
|
}
|
|
|
|
function addDeviceToTrack(data) {
|
|
const devArg = {
|
|
device: data[0],
|
|
owner: data[1],
|
|
mac: data[2].toUpperCase(),
|
|
};
|
|
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;
|