Resolv : DNS resolv library

更新时间:
2024-05-15
下载文档

Resolv : DNS resolv library

The resolv module provides a method to perform host name resolution. This module is available in EdgerOS 1.6.0 and later.

This module is the asynchronous mode of the resolv module. User can use the following code to import the resolv module.

var dns = require('async/resolv');

When the hostname cannot be queried, the query function will return undefined without throwing an asynchronous exception.

Support

The following shows dns module APIs available for each permissions.

 User ModePrivilege Mode
dns.lookup
dns.gethostbyname
dns.getaddrinfo
dns.cacheFlush

Dns Object

async dns.lookup(hostname[, domain])

  • hostname {String} Host name to be queried.
  • domain {Integer} socket.AF_INET or socket.AF_INET6. default: socket.AF_INET.
  • Returns: {String} IP address.

Find the IP address of the specified hostname. The domain name query process task is blocked until the query success or times out.

domain indicates the type of address required, must be socket.AF_INET or socket.AF_INET6, where the socket object is imported by the socket module:

var socket = require('socket');

Example

dns.lookup('www.edgeros.com').then(ipaddr => console.log(ipaddr), console.error);

async dns.gethostbyname(hostname[, domain])

  • hostname {String} Host name to be queried.
  • domain {Integer} socket.AF_INET or socket.AF_INET6. default: socket.AF_INET.
  • Returns: {Object} IP address object.

Same as dns.lookup() but returns object. If the query is correct, the returned object contains the following members:

  • addr {String} IP address string.
  • domain {Integer} socket.AF_INET or socket.AF_INET6.

Example

dns.gethostbyname('www.edgeros.com').then(res => console.log(res.addr), console.error);

async dns.getaddrinfo(hostname[, domain[, flags]])

  • hostname {String} Host name to be queried.
  • domain {Integer} socket.AF_INET or socket.AF_INET6. default: socket.AF_INET.
  • flags {Integer} Query flags. default: 0.
  • Returns: {Object} IP address object, same as dns.gethostbyname().

Find the IP address of the specified hostname. The domain name query process task is blocked until the query success or times out.

The following properties are flags which can be passed as hints for the dns.getaddrinfo() method.

  • dns.ADDRCONFIG {Number}

Returned address types are determined by the types of addresses supported by the current system.

  • dns.V4MAPPED {Number}

If the IPv6 family was specified, but no IPv6 addresses were found, then return IPv4 mapped IPv6 addresses.

dns.cacheFlush([hostname])

  • hostname {String} Hostname. default: all hostname cache flush.

Flush all DNS cache. If the hostname argument is specified, only the DNS cache of the specified hostname will be flushed.

文档内容是否对您有所帮助?
有帮助
没帮助