From a021a5d469643038b4e375a5ab5c0f1705e51085 Mon Sep 17 00:00:00 2001 From: Martin Murphy Date: Sat, 8 Jan 2022 11:24:23 -0600 Subject: [PATCH] Accomodate for apples elimination of BSSID from airport results --- lib/airport.js | 16 ++++++---------- test/airport.js | 2 +- test/fixtures/airport/airport01.txt | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/airport.js b/lib/airport.js index ce41671..63c4617 100644 --- a/lib/airport.js +++ b/lib/airport.js @@ -22,17 +22,13 @@ function parseOutput(str, callback) { let lines = str.split('\n'); for (let i = 1, l = lines.length; i < l; i++) { - let mac = lines[i].match(macRegex); - if (!mac) { - continue; - } - let macStart = lines[i].indexOf(mac[0]); - let elements = lines[i].substr(macStart).split(/[ ]+/); + if (lines[i] == '') continue; + let elements = lines[i].substr(51).split(/[ ]+/); wifis.push({ - 'ssid' : lines[i].substr(0, macStart).trim(), - 'mac' : elements[0].trim(), - 'channel': parseInt(elements[2].trim(), 10), - 'rssi' : parseInt(elements[1].trim(), 10) + 'ssid' : lines[i].substr(0,32).trim(), + 'mac' : lines[i].substr(33,17).trim(), + 'channel': parseInt(elements[1].trim(), 10), + 'rssi' : parseInt(elements[0].trim(), 10) }); } } diff --git a/test/airport.js b/test/airport.js index 71ef3ea..13e5c50 100644 --- a/test/airport.js +++ b/test/airport.js @@ -17,7 +17,7 @@ describe('airport', () => { assert.equal(info.length, 36); let ap = info[0]; - assert.equal(ap.mac, '00:35:1a:90:56:03'); + assert.equal(ap.mac, ''); assert.equal(ap.ssid, 'OurTest'); assert.equal(ap.rssi, -70); assert.strictEqual(ap.channel, 112); diff --git a/test/fixtures/airport/airport01.txt b/test/fixtures/airport/airport01.txt index 9fabbe1..1d3532e 100644 --- a/test/fixtures/airport/airport01.txt +++ b/test/fixtures/airport/airport01.txt @@ -1,5 +1,5 @@ SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group) - OurTest 00:35:1a:90:56:03 -70 112 Y CH WPA2(PSK/AES/AES) + OurTest -70 112 Y CH WPA2(PSK/AES/AES) OurDev 00:35:1a:90:56:04 -70 112 Y CH WPA2(PSK/AES/AES) PDANet1 00:35:1a:90:56:09 -70 112 Y CH WPA2(PSK/AES/AES) TEST-Wifi 00:35:1a:90:56:0f -70 112 Y CH WPA2(PSK/AES/AES)