From a66fffbba7226843c6826935df369d1f714e40f6 Mon Sep 17 00:00:00 2001 From: juanescarraga <32574306+juanescarraga@users.noreply.github.com> Date: Tue, 12 Nov 2019 12:30:08 -0500 Subject: [PATCH] Code refactor --- lib/network.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/network.js b/lib/network.js index e8178a4..a6d52dc 100644 --- a/lib/network.js +++ b/lib/network.js @@ -293,7 +293,7 @@ function getWindowsIfaceDNSsuffix(ifaces, ifacename) { } } -function getWindowsIEEE8021x(connectionType) { +function getWindowsIEEE8021x(connectionType, iface) { let i8021x = { state: 'Unknown', protocol: 'Unknown', @@ -302,9 +302,16 @@ function getWindowsIEEE8021x(connectionType) { try { const result = execSync('netsh lan show profiles', util.execOptsWin); - const arrayResult = result.split('\r\n'); + const arrayResult = result.split('\r\nProfile on interface'); + + // Get 802.1x information by interface name + const iface8021xInfo = arrayResult.find((element) => { + return element.includes(iface + '\r\n'); + }); - const state8021x = arrayResult.find((element) => { + const arrayIface8021xInfo = iface8021xInfo.split('\r\n') + + const state8021x = arrayIface8021xInfo.find((element) => { return element.includes('802.1x'); }); @@ -313,9 +320,10 @@ function getWindowsIEEE8021x(connectionType) { i8021x.protocol = "Not Configured"; return i8021x; } else { - const protocol8021x = arrayResult.find((element) => { + const protocol8021x = arrayIface8021xInfo.find((element) => { return element.includes('EAP'); }); + i8021x.protocol = protocol8021x.split(':').pop(); i8021x.state = "Enabled"; return i8021x; @@ -665,7 +673,7 @@ function networkInterfaces(callback) { type = detail.type; } }); - const IEEE8021x = getWindowsIEEE8021x(type); + const IEEE8021x = getWindowsIEEE8021x(type, dev); auth8021x = IEEE8021x.protocol; state8021x = IEEE8021x.state; if (dev.toLowerCase().indexOf('wlan') >= 0 || ifaceName.toLowerCase().indexOf('wlan') >= 0 || ifaceName.toLowerCase().indexOf('wireless') >= 0) {