Fix null error; Fix promise
This commit is contained in:
parent
4e8c3efe6f
commit
debd06f258
17
index.js
17
index.js
@ -70,7 +70,7 @@ function initTools(callback) {
|
|||||||
* @param {boolean} useSudo - Use sudo for access?
|
* @param {boolean} useSudo - Use sudo for access?
|
||||||
*/
|
*/
|
||||||
function scanNetworks(callback, useSudo) {
|
function scanNetworks(callback, useSudo) {
|
||||||
exec((useSudo && "sudo ") + scanner.cmdLine, function (err, stdout) {
|
exec((useSudo ? "sudo ":"") + scanner.cmdLine, function (err, stdout) {
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
return;
|
return;
|
||||||
@ -94,11 +94,20 @@ module.exports = {
|
|||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
scanner = s;
|
scanner = s;
|
||||||
scanNetworks(resolve, useSudo);
|
scanNetworks((err, result) => {
|
||||||
|
if(err)
|
||||||
|
return reject(err);
|
||||||
|
resolve(result);
|
||||||
|
}, useSudo);
|
||||||
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scanNetworks(resolve, useSudo);
|
scanNetworks((err, result) => {
|
||||||
} )
|
if(err)
|
||||||
|
return reject(err);
|
||||||
|
resolve(result);
|
||||||
|
}, useSudo);
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -26,7 +26,8 @@ function parseOutput(str, callback) {
|
|||||||
'ssid' : lines[i].substring(0, 32).trim(),
|
'ssid' : lines[i].substring(0, 32).trim(),
|
||||||
'mac' : '', // There is no more mac on a mac
|
'mac' : '', // There is no more mac on a mac
|
||||||
'channel': parseInt(elements[1].trim(), 10),
|
'channel': parseInt(elements[1].trim(), 10),
|
||||||
'rssi' : parseInt(elements[0].trim(), 10)
|
'rssi' : parseInt(elements[0].trim(), 10),
|
||||||
|
'encrypted': false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ const detector = tool + ' --help';
|
|||||||
|
|
||||||
const macRegex = /([0-9a-zA-Z]{1}[0-9a-zA-Z]{1}[:]{1}){5}[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}/;
|
const macRegex = /([0-9a-zA-Z]{1}[0-9a-zA-Z]{1}[:]{1}){5}[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}/;
|
||||||
const cellRegex = /Cell [0-9]{2,} - Address:/;
|
const cellRegex = /Cell [0-9]{2,} - Address:/;
|
||||||
|
const encryptedRegex = /Encryption key:on/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parsing the output of iwlist, tool having a lot of different faces :-(
|
* Parsing the output of iwlist, tool having a lot of different faces :-(
|
||||||
@ -27,7 +28,8 @@ function parseOutput(str, callback) {
|
|||||||
let blocks = str.split(cellRegex);
|
let blocks = str.split(cellRegex);
|
||||||
|
|
||||||
blocks.forEach(block => {
|
blocks.forEach(block => {
|
||||||
let network = {};
|
let network = {encrypted: encryptedRegex.test(block)};
|
||||||
|
|
||||||
let lines = block.split('\n');
|
let lines = block.split('\n');
|
||||||
if (macRegex.exec(lines[0])) {
|
if (macRegex.exec(lines[0])) {
|
||||||
// First line is the mac address (always! (?))
|
// First line is the mac address (always! (?))
|
||||||
|
@ -41,7 +41,7 @@ function parseOutput(str, callback) {
|
|||||||
// Basic rates (MBit/s) : 1 2 5.5 11
|
// Basic rates (MBit/s) : 1 2 5.5 11
|
||||||
// Other rates (MBit/s) : 6 9 12 18 24 36 48 54
|
// Other rates (MBit/s) : 6 9 12 18 24 36 48 54
|
||||||
for (let i = 1, l = blocks.length; i < l; i++) {
|
for (let i = 1, l = blocks.length; i < l; i++) {
|
||||||
let network = {};
|
let network = {encrypted: false};
|
||||||
let lines = blocks[i].split('\n');
|
let lines = blocks[i].split('\n');
|
||||||
let regexChannel = /[a-zA-Z0-9()\s]+:[\s]*[0-9]+$/g;
|
let regexChannel = /[a-zA-Z0-9()\s]+:[\s]*[0-9]+$/g;
|
||||||
if (!lines || lines.length < 2) {
|
if (!lines || lines.length < 2) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user