Code refactor only get onces Profile information

This commit is contained in:
ricardopolo 2019-11-12 14:59:50 -05:00
parent 16e7a2e81d
commit 746137ef47

View File

@ -295,19 +295,25 @@ function getWindowsIfaceDNSsuffix(ifaces, ifacename) {
}
}
function getWindowsIEEE8021x(connectionType, iface) {
function getWindowsWiredProfilesInformation() {
try {
const result = execSync('netsh lan show profiles', util.execOptsWin);
const profileList = result.split('\r\nProfile on interface');
return profileList;
} catch (error) {
return [];
}
}
function getWindowsIEEE8021x(connectionType, iface, ifaces) {
let i8021x = {
state: 'Unknown',
protocol: 'Unknown',
};
if(connectionType == 'wired'){
if(connectionType == 'wired' && ifaces.length > 0){
try {
const result = execSync('netsh lan show profiles', util.execOptsWin);
const arrayResult = result.split('\r\nProfile on interface');
// Get 802.1x information by interface name
const iface8021xInfo = arrayResult.find((element) => {
const iface8021xInfo = ifaces.find((element) => {
return element.includes(iface + '\r\n');
});
@ -534,6 +540,7 @@ function networkInterfaces(callback) {
let result = [];
let nics = [];
let dnsSuffixes = [];
let nics8021xInfo = [];
// seperate handling in OSX
if (_darwin || _freebsd || _openbsd || _netbsd) {
nics = getDarwinNics();
@ -568,6 +575,7 @@ function networkInterfaces(callback) {
} else {
_ifaces = ifaces;
if (_windows) {
nics8021xInfo = getWindowsWiredProfilesInformation();
nics = getWindowsNics();
dnsSuffixes = getWindowsDNSsuffixes();
}
@ -676,7 +684,7 @@ function networkInterfaces(callback) {
type = detail.type;
}
});
const IEEE8021x = getWindowsIEEE8021x(type, dev);
const IEEE8021x = getWindowsIEEE8021x(type, dev, nics8021xInfo);
auth8021x = IEEE8021x.protocol;
state8021x = IEEE8021x.state;
if (dev.toLowerCase().indexOf('wlan') >= 0 || ifaceName.toLowerCase().indexOf('wlan') >= 0 || ifaceName.toLowerCase().indexOf('wireless') >= 0) {