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 = [];
|
||||
if (wifiObj) {
|
||||
wifiObj.forEach(function (wifiItem) {
|
||||
@ -397,7 +397,7 @@ function parseWifiDarwin(wifiObj) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseWifi2Darwin(wifiStr) {
|
||||
function parseWifiDarwin(wifiStr) {
|
||||
const result = [];
|
||||
try {
|
||||
let wifiObj = JSON.parse(wifiStr);
|
||||
@ -418,15 +418,16 @@ function parseWifi2Darwin(wifiStr) {
|
||||
security.push('WPA3');
|
||||
}
|
||||
const channelInfo = new RegExp(/(\d+) \((\d)GHz, (\d+)MHz\)/g).exec(wifiItem.spairport_network_channel);
|
||||
const signalLevel = wifiItem.spairport_signal_noise || null;
|
||||
|
||||
result.push({
|
||||
ssid: wifiItem._name || '',
|
||||
bssid: '',
|
||||
bssid: wifiItem.spairport_network_bssid || '',
|
||||
mode: wifiItem.spairport_network_phymode,
|
||||
channel: parseInt(channelInfo[0].split(' ')[0]),
|
||||
frequency: wifiFrequencyFromChannel(channelInfo[1]),
|
||||
signalLevel: null,
|
||||
quality: null,
|
||||
signalLevel: signalLevel ? parseInt(signalLevel, 10) : null,
|
||||
quality: wifiQualityFromDB(signalLevel),
|
||||
security,
|
||||
wpaFlags: [],
|
||||
rsnFlags: []
|
||||
@ -500,15 +501,9 @@ function wifiNetworks(callback) {
|
||||
resolve(result);
|
||||
}
|
||||
} 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) {
|
||||
const output = stdout.toString();
|
||||
const parts = output.split('######');
|
||||
if (parts[0]) {
|
||||
result = parseWifiDarwin(util.plistParser(parts[0]));
|
||||
} else {
|
||||
result = parseWifi2Darwin(parts[1]);
|
||||
}
|
||||
result = parseWifiDarwin(stdout.toString());
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user