refactored wifiConections() (macOS)
This commit is contained in:
parent
8acbce7126
commit
8a801aec95
103
lib/wifi.js
103
lib/wifi.js
@ -645,86 +645,63 @@ function wifiConnections(callback) {
|
|||||||
}
|
}
|
||||||
resolve(result);
|
resolve(result);
|
||||||
} else if (_darwin) {
|
} else if (_darwin) {
|
||||||
let cmd = 'system_profiler SPNetworkDataType';
|
let cmd = 'system_profiler SPNetworkDataType SPAirPortDataType -xml 2>/dev/null; echo "######" ; ioreg -n AppleBCMWLANSkywalkInterface -r 2>/dev/null';
|
||||||
exec(cmd, function (error, stdout) {
|
|
||||||
const parts1 = stdout.toString().split('\n\n Wi-Fi:\n\n');
|
|
||||||
if (parts1.length > 1) {
|
|
||||||
const lines = parts1[1].split('\n\n')[0].split('\n');
|
|
||||||
const iface = util.getValue(lines, 'BSD Device Name', ':', true);
|
|
||||||
const model = util.getValue(lines, 'hardware', ':', true);
|
|
||||||
cmd = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I 2>/dev/null; echo "######" ; ioreg -n AppleBCMWLANSkywalkInterface -r 2>/dev/null';
|
|
||||||
exec(cmd, function (error, stdout) {
|
exec(cmd, function (error, stdout) {
|
||||||
|
try {
|
||||||
const parts = stdout.toString().split('######');
|
const parts = stdout.toString().split('######');
|
||||||
const lines2 = parts[0].split('\n');
|
const profilerObj = util.plistParser(parts[0]);
|
||||||
|
const networkObj = profilerObj[0]._SPCommandLineArguments.indexOf('SPNetworkDataType') >= 0 ? profilerObj[0]._items : profilerObj[1]._items;
|
||||||
|
const airportObj = profilerObj[0]._SPCommandLineArguments.indexOf('SPAirPortDataType') >= 0 ? profilerObj[0]._items[0].spairport_airport_interfaces : profilerObj[1]._items[0].spairport_airport_interfaces;
|
||||||
|
|
||||||
|
// parts[1] : ioreg
|
||||||
let lines3 = [];
|
let lines3 = [];
|
||||||
if (parts[1].indexOf(' | {') > 0 && parts[1].indexOf(' | }') > parts[1].indexOf(' | {')) {
|
if (parts[1].indexOf(' | {') > 0 && parts[1].indexOf(' | }') > parts[1].indexOf(' | {')) {
|
||||||
lines3 = parts[1].split(' | {')[1].split(' | }')[0].replace(/ \| /g, '').replace(/"/g, '').split('\n');
|
lines3 = parts[1].split(' | {')[1].split(' | }')[0].replace(/ \| /g, '').replace(/"/g, '').split('\n');
|
||||||
}
|
}
|
||||||
if (lines2.length > 10) {
|
|
||||||
const ssid = util.getValue(lines2, 'ssid', ':', true);
|
const networkWifiObj = networkObj.find((item) => { return item._name === 'Wi-Fi'; });
|
||||||
const bssid = util.getValue(lines2, 'bssid', ':', true) || formatBssid(util.getValue(lines3, 'IO80211BSSID', '=', true));
|
const airportWifiObj = airportObj[0].spairport_current_network_information;
|
||||||
const security = util.getValue(lines2, 'link auth', ':', true);
|
|
||||||
const txRate = util.getValue(lines2, 'lastTxRate', ':', true);
|
const channel = parseInt(('' + airportWifiObj.spairport_network_channel).split(' ')[0]) || 0;
|
||||||
const channel = util.getValue(lines2, 'channel', ':', true).split(',')[0];
|
const signalLevel = airportWifiObj.spairport_signal_noise || null;
|
||||||
const type = '802.11';
|
|
||||||
const rssi = util.toInt(util.getValue(lines2, 'agrCtlRSSI', ':', true));
|
let security = [];
|
||||||
/// const noise = util.toInt(util.getValue(lines2, 'agrCtlNoise', ':', true));
|
const sm = airportWifiObj.spairport_security_mode;
|
||||||
const signalLevel = rssi;
|
if (sm === 'spairport_security_mode_wep') {
|
||||||
if (ssid || bssid) {
|
security.push('WEP');
|
||||||
|
} else if (sm === 'spairport_security_mode_wpa2_personal') {
|
||||||
|
security.push('WPA2');
|
||||||
|
} else if (sm.startsWith('spairport_security_mode_wpa2_enterprise')) {
|
||||||
|
security.push('WPA2 EAP');
|
||||||
|
} else if (sm.startsWith('pairport_security_mode_wpa3_transition')) {
|
||||||
|
security.push('WPA2/WPA3');
|
||||||
|
} else if (sm.startsWith('pairport_security_mode_wpa3')) {
|
||||||
|
security.push('WPA3');
|
||||||
|
}
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
id: 'Wi-Fi',
|
id: networkWifiObj._name || 'Wi-Fi',
|
||||||
iface,
|
iface: networkWifiObj.interface || '',
|
||||||
model,
|
model: networkWifiObj.hardware || '',
|
||||||
ssid,
|
ssid: airportWifiObj._name || '',
|
||||||
bssid,
|
bssid: airportWifiObj.spairport_network_bssid || '',
|
||||||
channel: util.toInt(channel),
|
channel,
|
||||||
frequency: channel ? wifiFrequencyFromChannel(channel) : null,
|
frequency: channel ? wifiFrequencyFromChannel(channel) : null,
|
||||||
type,
|
type: airportWifiObj.spairport_network_phymode || '802.11',
|
||||||
security,
|
security,
|
||||||
signalLevel,
|
signalLevel: signalLevel ? parseInt(signalLevel, 10) : null,
|
||||||
quality: wifiQualityFromDB(signalLevel),
|
quality: wifiQualityFromDB(signalLevel),
|
||||||
txRate
|
txRate: airportWifiObj.spairport_network_rate || null,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
} catch (e) {
|
||||||
if (lines3.length > 10) {
|
util.noop();
|
||||||
const ssid = util.getValue(lines3, 'IO80211SSID', '=', true);
|
|
||||||
const bssid = formatBssid(util.getValue(lines3, 'IO80211BSSID', '=', true));
|
|
||||||
const security = '';
|
|
||||||
const txRate = -1;
|
|
||||||
const signalLevel = -1;
|
|
||||||
const quality = -1;
|
|
||||||
const channel = util.getValue(lines3, 'IO80211Channel', '=', true);
|
|
||||||
const type = '802.11';
|
|
||||||
if ((ssid || bssid) && !result.length) {
|
|
||||||
result.push({
|
|
||||||
id: 'Wi-Fi',
|
|
||||||
iface,
|
|
||||||
model,
|
|
||||||
ssid,
|
|
||||||
bssid,
|
|
||||||
channel: util.toInt(channel),
|
|
||||||
frequency: channel ? wifiFrequencyFromChannel(channel) : null,
|
|
||||||
type,
|
|
||||||
security,
|
|
||||||
signalLevel,
|
|
||||||
quality,
|
|
||||||
txRate
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(result);
|
callback(result);
|
||||||
}
|
}
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
if (callback) {
|
|
||||||
callback(result);
|
|
||||||
}
|
|
||||||
resolve(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (_windows) {
|
} else if (_windows) {
|
||||||
let cmd = 'netsh wlan show interfaces';
|
let cmd = 'netsh wlan show interfaces';
|
||||||
util.powerShell(cmd).then(function (stdout) {
|
util.powerShell(cmd).then(function (stdout) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user