dns.resolve() 编辑

Resolves the given hostname to a DNS record.

This is an asynchronous function that returns a Promise.

Syntax

var resolving = browser.dns.resolve(
  hostname,    // string
  flags        // array of string
)

Parameters

hostname
string. The hostname to resolve.
flags Optional
array of string. Flags to modify the way the hostname is resolved. Any omitted flags default to false. You can pass zero or more of the following flags:
  • "allow_name_collisions": Allow name collision results which are normally filtered out.
  • "bypass_cache": Suppresses the internal DNS lookup cache.
  • "canonical_name": The canonical name of the specified host will be queried.
  • "disable_ipv4": Only IPv6 addresses will be returned.
  • "disable_ipv6": Only IPv4 addresses will be returned.
  • "disable_trr": Do not use the Trusted Recursive Resolver (TRR) for resolving the host name. A TRR enables resolving of host names using a dedicated DNS-over-HTTPS server.
  • "offline": Only literals and cached entries will be returned.
  • "priority_low": The request is given lower priority. If "priority_medium" is also given, the query is given medium priority.
  • "priority_medium": The request is given medium priority. If "priority_low" is also given, the query is given medium priority.
  • "speculate": Indicates that the request is speculative. Speculative requests return errors if prefetching is disabled by the browser's configuration.

Return value

A Promise that will be fulfilled with a DNSRecord object. This object can contain the following properties:

addresses
array of string. The IP addresses associated with this DNS record.
canonicalName
string. The canonical name for this record. This is only included in the response if the "canonical_name" flag was passed to resolve().
isTRR
boolean: true if the record was retrieved using a Trusted Recursive Resolver (TRR).

Browser compatibility

BCD tables only load in the browser

Examples

function resolved(record) {
  console.log(record.addresses);
}

let resolving = browser.dns.resolve("example.com");
resolving.then(resolved);

// > e.g. Array [ "73.284.240.12" ]

Bypass the cache, and ask for the canonical name:

function resolved(record) {
  console.log(record.canonicalName);
  console.log(record.addresses);
}

let resolving = browser.dns.resolve("developer.mozilla.org",
                                   ["bypass_cache", "canonical_name"]);
resolving.then(resolved);

// > e.g. xyz.us-west-2.elb.amazonaws.com
// > e.g. Array [ "78.18.187.134", "34.79.135.234" ]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:119 次

字数:4499

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文