diff --git a/README.md b/README.md index 9966e2d..5920d91 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ The module was inspired from Maurice Sways "[node-wifiscanner](https://github.co had to handle much more complex network environments and also wanted to be independent of the operating system language. The adaptions needed would have been too comprehensive for a pull request so I decided to write an own module. +**The module is currently in BETA testing, changes in functionality and interface are possible. Please report bugs on the projects GitHub page, Thanks!** + ## Operating Systems It was tested with the following operating systems: @@ -29,6 +31,16 @@ It was tested with the following operating systems: console.log(networks); }); +The tool returns an array with objects, each object representing a network with the following properties: + +* channel: WiFi channel +* ssid: SSID of the network (if available) +* mac: MAC Address of the network access point +* rssi: signal strength + +In contrary to other wifi scanners no information about security is returned. This is due to the very different implementation +of the command line tools which do not allow a flawless detection. + ## Technical background The module uses command line tools for gathering the network information: diff --git a/lib/airport.js b/lib/airport.js index 9110b0b..739d449 100644 --- a/lib/airport.js +++ b/lib/airport.js @@ -30,8 +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()), - 'security': elements[3].trim() + 'rssi' : parseInt(elements[1].trim()) }); } } diff --git a/lib/iwlist.js b/lib/iwlist.js index b4e5780..627a95c 100644 --- a/lib/iwlist.js +++ b/lib/iwlist.js @@ -32,11 +32,10 @@ function parseOutput(str, callback) { // SSID if (line.indexOf('ESSID:') > 0) { network.ssid = _.trim(line.split(':')[1], '"'); - } - - // Security - else if (_.startsWith(line.trim(), 'IE:')) { - network.security = line.split(':')[1].trim(); + if (_.startsWith(network.ssid, '\\x00')) { + // The raspi 3 interprets a string terminator as character, it's an empty SSID + network.ssid = ''; + } } // Channel, an ugly thing to get it diff --git a/lib/netsh.js b/lib/netsh.js index 76d441c..b31116e 100644 --- a/lib/netsh.js +++ b/lib/netsh.js @@ -61,12 +61,12 @@ function parseOutput(str, callback) { // Network signal strength, identified by '%' var level = parseInt(lines[t].split(':')[1].split('%')[0].trim(), 10); - network.signal_level = (level / 2) - 100; + network.rssi = (level / 2) - 100; } else if (!network.channel) { // 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])) { + if (regexChannel.exec(lines[t].trim())) { network.channel = parseInt(lines[t].split(':')[1].trim()); } } diff --git a/lib/nmcli.js b/lib/nmcli.js index f0ac446..8fb9773 100644 --- a/lib/nmcli.js +++ b/lib/nmcli.js @@ -31,8 +31,7 @@ function parseOutput(str, callback) { 'ssid' : _.trim(lines[i].substr(0, macStart), ' \''), 'mac' : elements[0].trim(), 'channel' : parseInt(elements[2].trim(), 10), - 'rssi' : parseInt(elements[1].trim()), - 'security': 'TODO' + 'rssi' : parseInt(elements[1].trim()) }); } } diff --git a/test/fixtures/iwlist/iwlist03_raspi.txt b/test/fixtures/iwlist/iwlist03_raspi.txt index 061f38d..1abb3cd 100755 --- a/test/fixtures/iwlist/iwlist03_raspi.txt +++ b/test/fixtures/iwlist/iwlist03_raspi.txt @@ -4,7 +4,7 @@ wlan0 Scan completed : Frequency:2.412 GHz (Channel 1) Quality=39/70 Signal level=-71 dBm Encryption key:on - ESSID:"KABA-Wifi" + ESSID:"LORA-Wifi" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -66,7 +66,7 @@ wlan0 Scan completed : Frequency:2.412 GHz (Channel 1) Quality=41/70 Signal level=-69 dBm Encryption key:on - ESSID:"TenDev" + ESSID:"OppDev" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -97,7 +97,7 @@ wlan0 Scan completed : Frequency:2.412 GHz (Channel 1) Quality=42/70 Signal level=-68 dBm Encryption key:on - ESSID:"TenTest" + ESSID:"OppTest" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -249,7 +249,7 @@ wlan0 Scan completed : Frequency:2.412 GHz (Channel 1) Quality=24/70 Signal level=-86 dBm Encryption key:on - ESSID:"KABA-Wifi" + ESSID:"LORA-Wifi" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -312,7 +312,7 @@ wlan0 Scan completed : Frequency:2.437 GHz (Channel 6) Quality=32/70 Signal level=-78 dBm Encryption key:on - ESSID:"Kaba Training" + ESSID:"LORA Training" Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s 24 Mb/s; 36 Mb/s; 54 Mb/s Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s @@ -336,7 +336,7 @@ wlan0 Scan completed : Frequency:2.437 GHz (Channel 6) Quality=28/70 Signal level=-82 dBm Encryption key:on - ESSID:"KABA-Wifi" + ESSID:"LORA-Wifi" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -398,7 +398,7 @@ wlan0 Scan completed : Frequency:2.437 GHz (Channel 6) Quality=28/70 Signal level=-82 dBm Encryption key:on - ESSID:"TenDev" + ESSID:"OppDev" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -429,7 +429,7 @@ wlan0 Scan completed : Frequency:2.437 GHz (Channel 6) Quality=28/70 Signal level=-82 dBm Encryption key:on - ESSID:"TenTest" + ESSID:"OppTest" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -581,7 +581,7 @@ wlan0 Scan completed : Frequency:2.462 GHz (Channel 11) Quality=32/70 Signal level=-78 dBm Encryption key:on - ESSID:"KABA-Wifi" + ESSID:"LORA-Wifi" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -643,7 +643,7 @@ wlan0 Scan completed : Frequency:2.462 GHz (Channel 11) Quality=34/70 Signal level=-76 dBm Encryption key:on - ESSID:"TenDev" + ESSID:"OppDev" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -674,7 +674,7 @@ wlan0 Scan completed : Frequency:2.462 GHz (Channel 11) Quality=33/70 Signal level=-77 dBm Encryption key:on - ESSID:"TenTest" + ESSID:"OppTest" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -768,7 +768,7 @@ wlan0 Scan completed : Frequency:2.462 GHz (Channel 11) Quality=23/70 Signal level=-87 dBm Encryption key:on - ESSID:"TenDev" + ESSID:"OppDev" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master @@ -799,7 +799,7 @@ wlan0 Scan completed : Frequency:2.462 GHz (Channel 11) Quality=23/70 Signal level=-87 dBm Encryption key:on - ESSID:"TenTest" + ESSID:"OppTest" Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master diff --git a/test/fixtures/netsh/netsh_sp.txt b/test/fixtures/netsh/netsh_sp.txt index 916dc06..c578e58 100644 --- a/test/fixtures/netsh/netsh_sp.txt +++ b/test/fixtures/netsh/netsh_sp.txt @@ -24,7 +24,7 @@ SSID 2 : EZCastec-59A02EBA Velocidades b sicas (Mbps): 1 2 5.5 11 Otras velocidades (Mbps): 6 9 12 18 24 36 48 54 -SSID 3 : KABAWL3 +SSID 3 : LOLOWL3 Tipo de red : Infraestructura Autenticaci¢n : WPA2-Personal Cifrado : CCMP @@ -46,7 +46,7 @@ SSID 4 : IKMGUEST Velocidades b sicas (Mbps): 1 2 5.5 11 Otras velocidades (Mbps): 6 9 12 18 24 36 48 54 -SSID 5 : KABAWL +SSID 5 : LOLOWL Tipo de red : Infraestructura Autenticaci¢n : WPA2-Personal Cifrado : CCMP diff --git a/test/iwlist.js b/test/iwlist.js index c6247a4..4ded456 100644 --- a/test/iwlist.js +++ b/test/iwlist.js @@ -12,8 +12,6 @@ const iwlist = require('../lib/iwlist'); describe('iwlist', () => { it('parses the output of file 1', function(done) { iwlist.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures','iwlist','iwlist01_ubuntu1404.txt'), { encoding: 'utf8' }), (err, info) => { - - console.log(info); assert.ok(info); done(err); }); @@ -22,8 +20,37 @@ describe('iwlist', () => { it('parses the output of file 2', function(done) { iwlist.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures','iwlist','iwlist02_raspi.txt'), { encoding: 'utf8' }), (err, info) => { - console.log(info); assert.ok(info); + + var ap = info[0]; + assert.equal(ap.mac, 'D4:D1:84:50:76:45'); + assert.equal(ap.ssid, 'gsy-97796'); + assert.equal(ap.rssi, -76); + assert.strictEqual(ap.channel, 6); + + ap = info[2]; + assert.equal(ap.mac, '7C:B7:33:AE:3B:05'); + assert.equal(ap.ssid, 'visitor-18170'); + assert.equal(ap.rssi, -70); + assert.strictEqual(ap.channel, 9); + done(err); + }); + }); + it('parses the output of file 2', function(done) { + iwlist.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures','iwlist','iwlist03_raspi.txt'), { encoding: 'utf8' }), (err, info) => { + assert.ok(info); + + var ap = info[0]; + assert.equal(ap.mac, '00:35:1A:90:56:00'); + assert.equal(ap.ssid, 'LORA-Wifi'); + assert.equal(ap.rssi, -71); + assert.strictEqual(ap.channel, 1); + + ap = info[28]; + assert.equal(ap.mac, '00:35:1A:5B:45:B2'); + assert.equal(ap.ssid, ''); + assert.equal(ap.rssi, -89); + assert.strictEqual(ap.channel, 11); done(err); }); }); diff --git a/test/netsh.js b/test/netsh.js index 354571b..a7972f8 100644 --- a/test/netsh.js +++ b/test/netsh.js @@ -15,35 +15,35 @@ describe('netsh', function () { netsh.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures', 'netsh', 'netsh_de_complex01.txt'), {encoding: 'utf8'}), (err, info) => { assert.ok(info); assert.equal(info.length, 86); - + var ap = info[0]; assert.equal(ap.mac, '00:f2:8b:8c:a6:88'); assert.equal(ap.ssid, ''); - assert.equal(ap.signal_level, -88.5); + assert.equal(ap.rssi, -88.5); assert.strictEqual(ap.channel, 1); ap = info[22]; assert.equal(ap.mac, '00:35:1a:5b:46:7b'); assert.equal(ap.ssid, ''); - assert.equal(ap.signal_level, -90); + assert.equal(ap.rssi, -90); assert.strictEqual(ap.channel, 116); ap = info[23]; assert.equal(ap.mac, '10:bd:18:ab:4d:8f'); assert.equal(ap.ssid, 'Network-1'); - assert.equal(ap.signal_level, -81); + assert.equal(ap.rssi, -81); assert.strictEqual(ap.channel, 6); ap = info[74]; assert.equal(ap.mac, '00:f2:8b:8c:a6:8d'); assert.equal(ap.ssid, 'Network-6'); - assert.equal(ap.signal_level, -87.5); + assert.equal(ap.rssi, -87.5); assert.strictEqual(ap.channel, 1); ap = info[85]; assert.equal(ap.mac, '00:f2:8b:8c:a6:85'); assert.equal(ap.ssid, 'Network-7'); - assert.equal(ap.signal_level, -89.5); + assert.equal(ap.rssi, -89.5); assert.strictEqual(ap.channel, 1); done(err); }); @@ -54,38 +54,59 @@ describe('netsh', function () { netsh.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures', 'netsh', 'netsh_en_complex01.txt'), {encoding: 'utf8'}), (err, info) => { assert.ok(info); assert.equal(info.length, 86); - + var ap = info[0]; assert.equal(ap.mac, '00:f2:8b:8c:a6:88'); assert.equal(ap.ssid, ''); - assert.equal(ap.signal_level, -88.5); + assert.equal(ap.rssi, -88.5); assert.strictEqual(ap.channel, 1); ap = info[22]; assert.equal(ap.mac, '00:35:1a:5b:46:7b'); assert.equal(ap.ssid, ''); - assert.equal(ap.signal_level, -90); + assert.equal(ap.rssi, -90); assert.strictEqual(ap.channel, 116); ap = info[23]; assert.equal(ap.mac, '10:bd:18:ab:4d:8f'); assert.equal(ap.ssid, 'Network-1'); - assert.equal(ap.signal_level, -81); + assert.equal(ap.rssi, -81); assert.strictEqual(ap.channel, 6); ap = info[74]; assert.equal(ap.mac, '00:f2:8b:8c:a6:8d'); assert.equal(ap.ssid, 'Network-6'); - assert.equal(ap.signal_level, -87.5); + assert.equal(ap.rssi, -87.5); assert.strictEqual(ap.channel, 1); ap = info[85]; assert.equal(ap.mac, '00:f2:8b:8c:a6:85'); assert.equal(ap.ssid, 'Network-7'); - assert.equal(ap.signal_level, -89.5); + assert.equal(ap.rssi, -89.5); assert.strictEqual(ap.channel, 1); done(err); }); }); + + it('parses sp locale output', function (done) { + netsh.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures', 'netsh', 'netsh_sp.txt'), {encoding: 'utf8'}), (err, info) => { + assert.ok(info); + assert.equal(info.length, 8); + console.log(info); + var ap = info[0]; + assert.equal(ap.mac, '98:fc:11:b6:88:9e'); + assert.equal(ap.ssid, 'CARAMANZANAS_BAJA'); + assert.equal(ap.rssi, -86); + assert.strictEqual(ap.channel, 9); + + ap = info[7]; + assert.equal(ap.mac, '70:72:cf:af:51:e0'); + assert.equal(ap.ssid, 'BOOWIFI'); + assert.equal(ap.rssi, -100); + assert.strictEqual(ap.channel, 1); + done(); + }); + + }); }); diff --git a/test/nmcli.js b/test/nmcli.js index 0bac82f..6a23590 100644 --- a/test/nmcli.js +++ b/test/nmcli.js @@ -15,9 +15,13 @@ describe.skip('nmcli', () => { console.log(info); assert.ok(info); - assert.equal(info.length, 36); - + 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); });