diff --git a/lib/network.js b/lib/network.js index 1323b7e..c2b7294 100644 --- a/lib/network.js +++ b/lib/network.js @@ -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'){ - try { - - const result = execSync('netsh lan show profiles', util.execOptsWin); - const arrayResult = result.split('\r\nProfile on interface'); - + if(connectionType == 'wired' && ifaces.length > 0){ + try { // 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) {