From 53d79dca41af066d018cc3a0db73658e98e1de6f Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Wed, 27 Jan 2021 09:57:36 -0800 Subject: [PATCH] Added missing file --- modules/util-dns.js | 122 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 modules/util-dns.js diff --git a/modules/util-dns.js b/modules/util-dns.js new file mode 100644 index 0000000..36c2b08 --- /dev/null +++ b/modules/util-dns.js @@ -0,0 +1,122 @@ +/* +Copyright 2021 Intel Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +function windows_dns() +{ + var ret = []; + var ip = require('_GenericMarshal').CreateNativeProxy('Iphlpapi.dll'); + ip.CreateMethod('GetNetworkParams'); + + var data = require('_GenericMarshal').CreateVariable(1024); + var len = require('_GenericMarshal').CreateVariable(4); + len.toBuffer().writeUInt32LE(1024); + + if (ip.GetNetworkParams(data, len).Val == 0) + { + var dnsList = data.Deref(require('_GenericMarshal').PointerSize == 8 ? 272 : 268, 48); + + do + { + ret.push(dnsList.Deref(require('_GenericMarshal').PointerSize, 16).toBuffer().toString()); + } while ((dnsList = dnsList.Deref(0, require('_GenericMarshal').PointerSize).Deref().Deref(0, 48)).Val != 0); + } + return (ret); +} +function linux_dns() +{ + var child = require('child_process').execFile('/bin/sh', ['sh']); + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); + child.stderr.on('data', function () { }); + child.stdin.write("cat /etc/resolv.conf | grep nameserver | tr '\n' '`' | awk -F'`' '"); + child.stdin.write('{'); + child.stdin.write(' DEL="";'); + child.stdin.write(' printf "[";'); + child.stdin.write(' for(i=1;i