From 86389999de9dac07493fd15f6bd5b958f8550572 Mon Sep 17 00:00:00 2001 From: juanescarraga <32574306+juanescarraga@users.noreply.github.com> Date: Fri, 1 Nov 2019 12:13:48 -0500 Subject: [PATCH] fix some fool erros --- lib/network.js | 15 +++++++++------ test.js | 8 ++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 test.js diff --git a/lib/network.js b/lib/network.js index 4bf4b43..494517e 100644 --- a/lib/network.js +++ b/lib/network.js @@ -233,11 +233,13 @@ function getWindowsDNSsuffixes() { exitCode: 0, ifaces: [], }; - + try { const ipconfig = execSync('ipconfig /all', util.execOptsWin); - const ipconfigArray = ipconfig.output.split('\r\n\r\n'); + const ipconfigArray = ipconfig.split('\r\n\r\n'); + ipconfigArray.forEach( (element, index) => { + if(index == 1) { const longPrimaryDNS = element.split('\r\n').filter((element) => { return element.toUpperCase().includes('DNS'); @@ -261,9 +263,10 @@ function getWindowsDNSsuffixes() { } } }); + return dnsSuffixes; } catch (error) { - console.log('An error occurred trying to bring the DNS suffixes of the network ifaces', error.message); + console.log('An error occurred trying to bring the Connection-specific DNS suffix', error.message); return { primaryDNS: '', exitCode: 0, @@ -282,11 +285,11 @@ function getWindowsIfaceDNSsuffix(ifaces, ifacename) { if(connectionDnsSuffix[0]) { dnsSuffix = connectionDnsSuffix[0]; } - if(!dnsSuffix) dnsSuffix = 'not defined'; + if(!dnsSuffix) dnsSuffix = ''; return dnsSuffix ; } catch (error) { console.log('Error getting Connection-specific DNS suffix: ', error.message); - return ''; + return 'Unknow'; } } @@ -582,7 +585,7 @@ function networkInterfaces(callback) { if (iface === 'lo' || iface.startsWith('bond')) { type = 'virtual'; } } if (_windows) { - dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, detail.name); + dnsSuffix = getWindowsIfaceDNSsuffix(dnsSuffixes.ifaces, dev); nics.forEach(detail => { if (detail.mac === mac) { ifaceName = detail.name; diff --git a/test.js b/test.js new file mode 100644 index 0000000..01d7c0b --- /dev/null +++ b/test.js @@ -0,0 +1,8 @@ +const si = require('./lib/network'); + +async function test(){ + const result = await si.networkInterfaces(); + console.log(result); +} + +test(); \ No newline at end of file