51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
const { format, promisify } = require('util');
|
|
const exec = promisify(require('child_process').exec);
|
|
|
|
/* async function parseDig(output) {
|
|
console.log('parseDig', output);
|
|
const lines = output.split(/\n/);
|
|
const result = {
|
|
'A': [],
|
|
'CNAME': []
|
|
};
|
|
for (const line of lines) {
|
|
if (/^A (.*) from/.test(line)) {
|
|
const scn = line.match(/^A (.*). from/)[1];
|
|
result.A.push(scn);
|
|
}
|
|
if (/^CNAME (.*) from/.test(line)) {
|
|
const scn = line.match(/^CNAME (.*). from/)[1];
|
|
result.CNAME.push(scn);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}*/
|
|
|
|
/**
|
|
* Dig trace option wrapper method.
|
|
*
|
|
* @param {String} name
|
|
* @returns {{A: String[], CNAME: String[]}} results
|
|
*/
|
|
function dig(name) {
|
|
return new Promise(async (resolve, reject) => {
|
|
if (typeof (name) !== 'string')
|
|
throw new TypeError('name (string) is required');
|
|
|
|
const cmd = format('dig %s +time=3 +retry=1', name);
|
|
console.log('CMD', cmd);
|
|
const { stdout, stderr } = await exec(cmd, { 'maxBuffer': 1024 * 1024 });
|
|
// console.log('output', stdout, stderr);
|
|
try {
|
|
resolve(stdout);
|
|
}
|
|
catch (e) {
|
|
reject(e);
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = dig;
|
|
module.exports.default = dig;
|