Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
6f44b5b039 | |||
2caacc853a | |||
de5cde2ca9 | |||
7cf077d527 | |||
253b375923 | |||
f22300b438 | |||
a15dd29c53 |
8
.travis.yml
Normal file
8
.travis.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
language: node_js
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- develop
|
||||||
|
node_js:
|
||||||
|
- "4"
|
||||||
|
- "5"
|
@ -1,5 +1,9 @@
|
|||||||
#node-wifi-scanner
|
#node-wifi-scanner
|
||||||
|
|
||||||
|
[](https://travis-ci.org/ancasicolica/node-wifi-scanner)
|
||||||
|
[]()
|
||||||
|
[](https://www.npmjs.com/package/node-wifi-scanner)
|
||||||
|
|
||||||
This module for node.js scans available wifi networks. The main purpose was to enhance my node.js based
|
This module for node.js scans available wifi networks. The main purpose was to enhance my node.js based
|
||||||
[ZigBee Site Survey Tool](http://ancasicolica.github.io/ZigBeeSiteSurvey/) with WiFi coexistence charts. This tool
|
[ZigBee Site Survey Tool](http://ancasicolica.github.io/ZigBeeSiteSurvey/) with WiFi coexistence charts. This tool
|
||||||
claims to be compatible with current versions of Mac OS-X, Windows and Linux so I'll fix bugs as fast as possible.
|
claims to be compatible with current versions of Mac OS-X, Windows and Linux so I'll fix bugs as fast as possible.
|
||||||
@ -81,3 +85,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
15
index.js
15
index.js
@ -8,7 +8,6 @@ const exec = require('child_process').exec;
|
|||||||
// The tools
|
// The tools
|
||||||
const airport = require('./lib/airport');
|
const airport = require('./lib/airport');
|
||||||
const iwlist = require('./lib/iwlist');
|
const iwlist = require('./lib/iwlist');
|
||||||
const nmcli = require('./lib/nmcli');
|
|
||||||
const netsh = require('./lib/netsh');
|
const netsh = require('./lib/netsh');
|
||||||
|
|
||||||
var scanner;
|
var scanner;
|
||||||
@ -24,19 +23,11 @@ function initTools(callback) {
|
|||||||
if (stats) {
|
if (stats) {
|
||||||
return callback(null, iwlist);
|
return callback(null, iwlist);
|
||||||
}
|
}
|
||||||
|
fs.stat(netsh.tool, function (err, stats) {
|
||||||
fs.stat(nmcli.tool, function (err, stats) {
|
|
||||||
if (stats) {
|
if (stats) {
|
||||||
return callback(null, nmcli);
|
return callback(null, netsh);
|
||||||
}
|
}
|
||||||
|
callback(new Error('No scanner found'));
|
||||||
fs.stat(netsh.tool, function (err, stats) {
|
|
||||||
if (stats) {
|
|
||||||
return callback(null, netsh);
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(new Error('No scanner found'));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -18,9 +18,13 @@ function parseOutput(str, callback) {
|
|||||||
var wifis = [];
|
var wifis = [];
|
||||||
var err = null;
|
var err = null;
|
||||||
try {
|
try {
|
||||||
|
if (blocks.length < 2) {
|
||||||
|
// 2nd try, with \r\n
|
||||||
|
blocks = str.split('\r\n\r\n')
|
||||||
|
}
|
||||||
if (!blocks || blocks.length === 1) {
|
if (!blocks || blocks.length === 1) {
|
||||||
// No WiFis found
|
// No WiFis found
|
||||||
return [];
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Each block has the same structure, while some parts might be available and others
|
// Each block has the same structure, while some parts might be available and others
|
||||||
|
50
lib/nmcli.js
50
lib/nmcli.js
@ -1,50 +0,0 @@
|
|||||||
/**
|
|
||||||
* Scanning WiFis on Mac OS X using nmcli
|
|
||||||
* Created by kc on 04.04.16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const _ = require('lodash');
|
|
||||||
const tool = '/usr/bin/nmcli';
|
|
||||||
const cmdLine = tool + ' -m tabular -f SSID,BSSID,SIGNAL,FREQ device wifi';
|
|
||||||
|
|
||||||
const macRegex = /([0-9a-zA-Z]{1}[0-9a-zA-Z]{1}[:]{1}){5}[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}/;
|
|
||||||
/**
|
|
||||||
* Parsing the output of nmcli
|
|
||||||
* @param str output of the tool
|
|
||||||
* @param callback
|
|
||||||
*/
|
|
||||||
function parseOutput(str, callback) {
|
|
||||||
var err = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
var lines = str.split('\n');
|
|
||||||
var wifis = [];
|
|
||||||
|
|
||||||
for (var i = 1, l = lines.length; i < l; i++) {
|
|
||||||
var mac = lines[i].match(macRegex);
|
|
||||||
if (!mac) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var macStart = lines[i].indexOf(mac[0]);
|
|
||||||
var elements = lines[i].substr(macStart).split(/[ ]+/);
|
|
||||||
wifis.push({
|
|
||||||
'ssid' : _.trim(lines[i].substr(0, macStart), ' \''),
|
|
||||||
'mac' : elements[0].trim(),
|
|
||||||
'channel' : parseInt(elements[2].trim(), 10),
|
|
||||||
'rssi' : parseInt(elements[1].trim())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (ex) {
|
|
||||||
err = ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(err, wifis);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
parseOutput: parseOutput,
|
|
||||||
cmdLine : cmdLine,
|
|
||||||
tool : tool
|
|
||||||
};
|
|
17
package.json
17
package.json
@ -1,19 +1,27 @@
|
|||||||
{
|
{
|
||||||
"name": "node-wifi-scanner",
|
"name": "node-wifi-scanner",
|
||||||
"version": "0.0.4",
|
"version": "0.1.0",
|
||||||
"description": "node.js module for WiFi network detection",
|
"description": "node.js module for WiFi network detection",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"WiFi",
|
"WiFi",
|
||||||
"Node.js",
|
"Node.js",
|
||||||
"scanner"
|
"scanner",
|
||||||
|
"airport",
|
||||||
|
"netsh",
|
||||||
|
"iwlist",
|
||||||
|
"nmcli"
|
||||||
],
|
],
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Christian Kuster, CH-8342 Wernetshausen",
|
"name": "Christian Kuster, CH-8342 Wernetshausen",
|
||||||
"email": "info@kusti.ch",
|
"email": "info@kusti.ch",
|
||||||
"url": "http://www.kusti.ch/"
|
"url": "http://www.kusti.ch/"
|
||||||
},
|
},
|
||||||
"homepage": "http://www.ferropoly.ch/",
|
"homepage": "https://github.com/ancasicolica/node-wifi-scanner",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/ancasicolica/node-wifi-scanner/issues",
|
||||||
|
"email": "info@ancasicolica.ch"
|
||||||
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -31,6 +39,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "0.4.5",
|
"grunt": "0.4.5",
|
||||||
"grunt-bump": "0.7.0"
|
"grunt-bump": "0.7.0",
|
||||||
|
"mocha": "2.2.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
test/fixtures/nmcli/nmcli01.txt
vendored
20
test/fixtures/nmcli/nmcli01.txt
vendored
@ -1,20 +0,0 @@
|
|||||||
SSID BSSID SIGNAL FREQUENZ
|
|
||||||
'PDANet1' 00:35:1A:90:56:06 100 2412 MHz
|
|
||||||
'ExoNet1' 00:35:1A:90:56:05 100 2412 MHz
|
|
||||||
'TEST-Wifi' 00:35:1A:90:56:00 96 2412 MHz
|
|
||||||
'OurTest' 00:35:1A:90:56:0C 96 2412 MHz
|
|
||||||
'OurDev' 00:35:1A:90:56:0B 76 2412 MHz
|
|
||||||
'PDANet1' 00:35:1A:6F:0F:46 48 2437 MHz
|
|
||||||
'TEST-Wifi' 00:35:1A:6F:0F:40 58 2437 MHz
|
|
||||||
'ExoNet1' 00:35:1A:6F:0F:45 58 2437 MHz
|
|
||||||
'OurDev' 00:35:1A:6F:0F:4B 58 2437 MHz
|
|
||||||
'OurTest' 00:35:1A:6F:0F:4C 60 2437 MHz
|
|
||||||
'TEST-Wifi' 00:F2:8B:8F:58:70 58 2462 MHz
|
|
||||||
'ExoNet1' 00:F2:8B:8F:58:75 72 2462 MHz
|
|
||||||
'PDANet1' 00:F2:8B:8F:58:76 58 2462 MHz
|
|
||||||
'PDANet1' 00:35:1A:5B:46:76 56 2412 MHz
|
|
||||||
'OurDev' 00:35:1A:5B:46:7B 48 2412 MHz
|
|
||||||
'OurDev' 00:F2:8B:8F:58:7B 58 2462 MHz
|
|
||||||
'OurTest' 00:F2:8B:8F:58:7C 72 2462 MHz
|
|
||||||
'TEST-Wifi' 00:35:1A:5B:46:70 56 2412 MHz
|
|
||||||
'OurTest' 00:35:1A:5B:46:7C 48 2412 MHz
|
|
@ -93,7 +93,7 @@ describe('netsh', function () {
|
|||||||
netsh.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures', 'netsh', 'netsh_sp.txt'), {encoding: 'utf8'}), (err, info) => {
|
netsh.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures', 'netsh', 'netsh_sp.txt'), {encoding: 'utf8'}), (err, info) => {
|
||||||
assert.ok(info);
|
assert.ok(info);
|
||||||
assert.equal(info.length, 8);
|
assert.equal(info.length, 8);
|
||||||
console.log(info);
|
|
||||||
var ap = info[0];
|
var ap = info[0];
|
||||||
assert.equal(ap.mac, '98:fc:11:b6:88:9e');
|
assert.equal(ap.mac, '98:fc:11:b6:88:9e');
|
||||||
assert.equal(ap.ssid, 'CARAMANZANAS_BAJA');
|
assert.equal(ap.ssid, 'CARAMANZANAS_BAJA');
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
/**
|
|
||||||
* nmcli unit test
|
|
||||||
* Created by kc on 04.04.16.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
const nmcli = require('../lib/nmcli');
|
|
||||||
|
|
||||||
describe.skip('nmcli', () => {
|
|
||||||
it('parses the output of file 1', function(done) {
|
|
||||||
nmcli.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures','nmcli','nmcli01.txt'), { encoding: 'utf8' }), (err, info) => {
|
|
||||||
|
|
||||||
console.log(info);
|
|
||||||
assert.ok(info);
|
|
||||||
assert.equal(info.length, 19);
|
|
||||||
|
|
||||||
var ap = info[0];
|
|
||||||
assert.equal(ap.mac, '00:35:1A:90:56:06');
|
|
||||||
assert.equal(ap.ssid, 'PDANet1');
|
|
||||||
//assert.equal(ap.rssi, -70);
|
|
||||||
assert.strictEqual(ap.channel, 112);
|
|
||||||
|
|
||||||
done(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
Reference in New Issue
Block a user