为了账号安全,请及时绑定邮箱和手机立即绑定

如何将 DNS 输出存储在 nodejs 中的变量中

如何将 DNS 输出存储在 nodejs 中的变量中

慕哥6287543 2021-10-21 10:40:37
如何将 dns.lookup 的返回值存储在变量中?如果我将它存储在一个数组中,它会显示为空白。以下是我正在处理的代码:    const dns = require('dns');    class Network    {        search(host)        {            let options = {                hints: dns.ADDRCONFIG | dns.V4MAPPED,                all: true,                verbatim: true           }           let addr = [];           dns.lookup(host, options, (error, address) =>               {                   if(error)                   {                       console.log("Could not resolve %s\n", host);                       console.log(error);                   }                   address.forEach(ip => {                       addr.push({                           address: ip.address,                           family: ip.family                       });                   });               });           console.log(addr);           return addr;       }   }      const network = new Network();   let output = network.search("www.google.com");   console.log(output);代码的输出为空白即 []请提出补救措施。
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 157 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号