2 Commits

Author SHA1 Message Date
77da84a261 Merge branch 'develop'
# Conflicts:
#	README.md
2016-05-03 14:55:40 +02:00
9669064662 readme.md fixed: removed nmcli 2016-04-12 17:25:00 +02:00
6 changed files with 25 additions and 61 deletions

View File

@ -53,7 +53,8 @@ The module uses command line tools for gathering the network information:
* airport on Mac OS-X: `airport -s`
* netsh on Windows: `netsh wlan show networks mode=Bssid`
* iwlist (1st choice) on Linux: `iwlist scan`
* iwlist on Linux: `iwlist scan`
Unfortunately, Mac OS-X and Windows use the system language for the output which requires a quite
generic way of parsing the data. If you experience any troubles, please create a GitHub issue and supply

View File

@ -5,8 +5,6 @@
const fs = require('fs');
const exec = require('child_process').exec;
const async = require('async');
const _ = require('lodash');
// The tools
const airport = require('./lib/airport');
const iwlist = require('./lib/iwlist');
@ -16,50 +14,25 @@ var scanner;
// Initializing the tools
function initTools(callback) {
// When a command is not found, an error is issued and async would finish. Therefore we pack
// the error into the result and check it later on.
async.parallel([
function (cb) {
exec(airport.detector, function (err) {
cb(null, {err: err, scanner: airport}
)
}
);
},
function (cb) {
exec(iwlist.detector, function (err) {
cb(null, {err: err, scanner: iwlist}
)
}
);
},
function (cb) {
exec(netsh.detector, function (err) {
cb(null, {err: err, scanner: netsh}
)
}
);
}
],
function (err, results) {
var res = _.find(results,
function (f) {
return !f.err
});
if (res) {
return callback(null, res.scanner);
}
callback(new Error('No scanner found'));
fs.stat(airport.tool, function (err, stats) {
if (stats) {
return callback(null, airport);
}
);
fs.stat(iwlist.tool, function (err, stats) {
if (stats) {
return callback(null, iwlist);
}
fs.stat(netsh.tool, function (err, stats) {
if (stats) {
return callback(null, netsh);
}
callback(new Error('No scanner found'));
});
});
});
}
/**
* Scan the networks with the scanner detected before
* @param callback
*/
function scanNetworks(callback) {
exec(scanner.cmdLine, function (err, stdout) {
if (err) {
@ -77,7 +50,7 @@ module.exports = {
*/
scan: function (callback) {
if (!scanner) {
initTools(function (err, s) {
initTools((err, s) => {
if (err) {
return callback(err);
}

View File

@ -5,7 +5,6 @@
const tool = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport';
const cmdLine = tool + ' -s';
const detector = tool + ' -getInfo';
const macRegex = /([0-9a-zA-Z]{1}[0-9a-zA-Z]{1}[:]{1}){5}[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}/;
/**
@ -31,7 +30,7 @@ function parseOutput(str, callback) {
'ssid' : lines[i].substr(0, macStart).trim(),
'mac' : elements[0].trim(),
'channel' : parseInt(elements[2].trim(), 10),
'rssi' : parseInt(elements[1].trim(), 10)
'rssi' : parseInt(elements[1].trim())
});
}
}
@ -46,6 +45,5 @@ function parseOutput(str, callback) {
module.exports = {
parseOutput: parseOutput,
cmdLine : cmdLine,
detector : detector,
tool : tool
};

View File

@ -4,12 +4,8 @@
*/
const _ = require('lodash');
// usually located in /usr/bin/ but as it could be at another location, allow all found in PATH (but we're in trouble
// when the default location, /usr/bin/ is not in the PATH!). GitHub issue #1
const tool = 'iwlist';
const tool = '/usr/bin/iwlist';
const cmdLine = tool + ' scan';
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 cellRegex = /Cell [0-9]{2,} - Address:/;
@ -83,6 +79,5 @@ function parseOutput(str, callback) {
module.exports = {
parseOutput: parseOutput,
cmdLine : cmdLine,
detector : detector,
tool : tool
};

View File

@ -6,7 +6,6 @@
const systemRoot = process.env.SystemRoot || 'C:\\Windows';
const tool = systemRoot + '\\System32\\netsh.exe';
const cmdLine = tool + ' wlan show networks mode=Bssid';
const detector = tool + ' show alias';
/**
* Parsing netnsh output. Unfortunately netsh supplies the network information
@ -72,7 +71,7 @@ function parseOutput(str, callback) {
// A tricky one: the channel is the first one having just ONE number. Set only
// if the channel is not already set ("Basic Rates" can be a single number also)
if (regexChannel.exec(lines[t].trim())) {
network.channel = parseInt(lines[t].split(':')[1].trim(), 10);
network.channel = parseInt(lines[t].split(':')[1].trim());
}
}
}
@ -91,6 +90,5 @@ function parseOutput(str, callback) {
module.exports = {
parseOutput: parseOutput,
cmdLine : cmdLine,
detector : detector,
tool : tool
};

View File

@ -1,6 +1,6 @@
{
"name": "node-wifi-scanner",
"version": "1.1.0",
"version": "1.0.0",
"description": "node.js module for WiFi network detection",
"main": "index.js",
"keywords": [
@ -35,8 +35,7 @@
"test": "mocha test"
},
"dependencies": {
"async": "2.1.4",
"lodash": "4.17.2"
"lodash": "4.8.1"
},
"devDependencies": {
"grunt": "0.4.5",