wifiNetworks() refactored parsing (macOS)
This commit is contained in:
parent
cea12c50b6
commit
51c89c1f1c
21
lib/wifi.js
21
lib/wifi.js
@ -345,7 +345,7 @@ function getWifiNetworkListIw(iface) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseWifiDarwin(wifiObj) {
|
function parseWifiDarwinXX(wifiObj) {
|
||||||
const result = [];
|
const result = [];
|
||||||
if (wifiObj) {
|
if (wifiObj) {
|
||||||
wifiObj.forEach(function (wifiItem) {
|
wifiObj.forEach(function (wifiItem) {
|
||||||
@ -397,7 +397,7 @@ function parseWifiDarwin(wifiObj) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseWifi2Darwin(wifiStr) {
|
function parseWifiDarwin(wifiStr) {
|
||||||
const result = [];
|
const result = [];
|
||||||
try {
|
try {
|
||||||
let wifiObj = JSON.parse(wifiStr);
|
let wifiObj = JSON.parse(wifiStr);
|
||||||
@ -418,15 +418,16 @@ function parseWifi2Darwin(wifiStr) {
|
|||||||
security.push('WPA3');
|
security.push('WPA3');
|
||||||
}
|
}
|
||||||
const channelInfo = new RegExp(/(\d+) \((\d)GHz, (\d+)MHz\)/g).exec(wifiItem.spairport_network_channel);
|
const channelInfo = new RegExp(/(\d+) \((\d)GHz, (\d+)MHz\)/g).exec(wifiItem.spairport_network_channel);
|
||||||
|
const signalLevel = wifiItem.spairport_signal_noise || null;
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
ssid: wifiItem._name || '',
|
ssid: wifiItem._name || '',
|
||||||
bssid: '',
|
bssid: wifiItem.spairport_network_bssid || '',
|
||||||
mode: wifiItem.spairport_network_phymode,
|
mode: wifiItem.spairport_network_phymode,
|
||||||
channel: parseInt(channelInfo[0].split(' ')[0]),
|
channel: parseInt(channelInfo[0].split(' ')[0]),
|
||||||
frequency: wifiFrequencyFromChannel(channelInfo[1]),
|
frequency: wifiFrequencyFromChannel(channelInfo[1]),
|
||||||
signalLevel: null,
|
signalLevel: signalLevel ? parseInt(signalLevel, 10) : null,
|
||||||
quality: null,
|
quality: wifiQualityFromDB(signalLevel),
|
||||||
security,
|
security,
|
||||||
wpaFlags: [],
|
wpaFlags: [],
|
||||||
rsnFlags: []
|
rsnFlags: []
|
||||||
@ -500,15 +501,9 @@ function wifiNetworks(callback) {
|
|||||||
resolve(result);
|
resolve(result);
|
||||||
}
|
}
|
||||||
} else if (_darwin) {
|
} else if (_darwin) {
|
||||||
let cmd = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s -x >2 /dev/bull; echo "######"; system_profiler -json SPAirPortDataType';
|
let cmd = 'system_profiler SPAirPortDataType -json 2>/dev/null';
|
||||||
exec(cmd, { maxBuffer: 1024 * 40000 }, function (error, stdout) {
|
exec(cmd, { maxBuffer: 1024 * 40000 }, function (error, stdout) {
|
||||||
const output = stdout.toString();
|
result = parseWifiDarwin(stdout.toString());
|
||||||
const parts = output.split('######');
|
|
||||||
if (parts[0]) {
|
|
||||||
result = parseWifiDarwin(util.plistParser(parts[0]));
|
|
||||||
} else {
|
|
||||||
result = parseWifi2Darwin(parts[1]);
|
|
||||||
}
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(result);
|
callback(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user