dns.lookup 中的哪些选项可以获取所有地址?
Whichs options in dns.lookup to get all addresses?
我正在尝试使用 nodejs
的 dns
模块来获取与主机名关联的所有地址。我的代码是:
} else {
var host = m[1];
var options = {
all: true
}
dns.lookup(host, options, function (err, addresses) {
if (err) {
var s = "Couldn't resolve hostname " + host + ". Skipping.";
nba.sendMessage(msg.from.id, s.toString('utf8'));
}
else {
var s = '';
addresses.forEach(function (address) {
s += host + " has " + address.family + " address " + address.address + "\n";
});
nba.sendMessage(msg.from.id, s.toString('utf8'));
}
});
}
我收到以下错误:
dns.js:91
throw new Error('invalid argument: `family` must be 4 or 6');
^
Error: invalid argument: `family` must be 4 or 6
at Object.exports.lookup (dns.js:91:13)
at Object.exports.processMessage (/home/francesco/Dropbox/Informatica/Programmazione/MyPingBot/MessageProcessor.js:86:11)
at IncomingMessage.<anonymous> (/home/francesco/Dropbox/Informatica/Programmazione/MyPingBot/NodeBotAPI.js:75:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
但我不明白为什么。在文档 (https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) 中我读到:
Alternatively, options can be an object containing these properties:
family {Number} - The record family. If present, must be the integer 4 or 6. If not provided, both IP v4 and v6 addresses are accepted.
hints: {Number} - If present, it should be one or more of the supported getaddrinfo flags. If hints is not provided, then no flags are passed to getaddrinfo. Multiple flags can be passed through hints by logically ORing their values. See supported getaddrinfo flags below for more information on supported flags.
all: {Boolean} - When true, the callback returns all resolved addresses in an array, otherwise returns a single address. Defaults to false.
All properties are optional.
all
选项是在 633a99084 中添加的,首次出现在 io.js v1.2.0 中。这也意味着任何节点 v0.10 或 v0.12 版本都不会具有此功能。
我正在尝试使用 nodejs
的 dns
模块来获取与主机名关联的所有地址。我的代码是:
} else {
var host = m[1];
var options = {
all: true
}
dns.lookup(host, options, function (err, addresses) {
if (err) {
var s = "Couldn't resolve hostname " + host + ". Skipping.";
nba.sendMessage(msg.from.id, s.toString('utf8'));
}
else {
var s = '';
addresses.forEach(function (address) {
s += host + " has " + address.family + " address " + address.address + "\n";
});
nba.sendMessage(msg.from.id, s.toString('utf8'));
}
});
}
我收到以下错误:
dns.js:91
throw new Error('invalid argument: `family` must be 4 or 6');
^
Error: invalid argument: `family` must be 4 or 6
at Object.exports.lookup (dns.js:91:13)
at Object.exports.processMessage (/home/francesco/Dropbox/Informatica/Programmazione/MyPingBot/MessageProcessor.js:86:11)
at IncomingMessage.<anonymous> (/home/francesco/Dropbox/Informatica/Programmazione/MyPingBot/NodeBotAPI.js:75:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
但我不明白为什么。在文档 (https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) 中我读到:
Alternatively, options can be an object containing these properties:
family {Number} - The record family. If present, must be the integer 4 or 6. If not provided, both IP v4 and v6 addresses are accepted.
hints: {Number} - If present, it should be one or more of the supported getaddrinfo flags. If hints is not provided, then no flags are passed to getaddrinfo. Multiple flags can be passed through hints by logically ORing their values. See supported getaddrinfo flags below for more information on supported flags.
all: {Boolean} - When true, the callback returns all resolved addresses in an array, otherwise returns a single address. Defaults to false.
All properties are optional.
all
选项是在 633a99084 中添加的,首次出现在 io.js v1.2.0 中。这也意味着任何节点 v0.10 或 v0.12 版本都不会具有此功能。