Skip to content

Instantly share code, notes, and snippets.

@loderunner
Last active September 4, 2023 14:34
Show Gist options
  • Save loderunner/8723a7e790322fc13591d0c18cf97fec to your computer and use it in GitHub Desktop.
Save loderunner/8723a7e790322fc13591d0c18cf97fec to your computer and use it in GitHub Desktop.
Node dns.resolve issue
const dns = require("node:dns/promises");
const os = require("node:os");
const process = require("node:process");
function log(s) {
console.log(`${new Date().toISOString().slice(11, -1)} - ${s}`);
}
let interfaces;
function checkInterfaces() {
const ifs = os.networkInterfaces();
if (JSON.stringify(ifs) !== JSON.stringify(interfaces)) {
log("New network configuration:");
for (let [k, v] of Object.entries(ifs)) {
v = v.filter((i) => i.family === "IPv4");
if (v.length === 0) {
continue;
}
process.stdout.write(`\t${k}: ${v.map((i) => i.address)}\n`);
}
interfaces = ifs;
}
}
async function resolve() {
try {
checkInterfaces();
log("resolving scrt.run...");
await dns.resolve("scrt.run");
log("success");
} catch (err) {
log(err);
}
setTimeout(resolve, 5000);
}
resolve();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment