我正在尝试从终端读取站点名称并执行 dnslookup 以在屏幕上打印其 IP,但以下代码由于某种原因引发错误,这是代码
process.stdout.write('Enter the website name:<www.sitename.com>: ');
process.stdin.resume();
var dns = require('dns');
process.stdin.on('data',function(site) {
var lookup = site.toString('utf-8');
console.log(lookup);
dns.lookup(lookup,function(err,ip) {
if (err) throw err;
console.log(ip);
});
});
错误是 if (err) throw err; ^ 错误:getaddrinfo ENOENT at errnoException (dns.js:31:11) at Object.onanswer [as oncomplete] (dns.js:123:16)
为什么代码不起作用?