dns.lookupService(address, port, callback)


将参数addressport传入操作系统底层getnameinfo服务来解析处理并返回主机名。

如果address不是有效的IP地址,会抛出TypeErrorport必须是一个整数.如果不是规定的端口号,会抛出TypeError.

出错情况下,err是一个Error对象,err.code代码错误码。

const dns = require('dns');
dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
  console.log(hostname, service);
  // Prints: localhost ssh
});

如果以 util.promisify() 方式进行调用, 它将返回一个包含hostnameservice属性的 Promise 对象。

Resolves the given address and port into a hostname and service using the operating system's underlying getnameinfo implementation.

If address is not a valid IP address, a TypeError will be thrown. The port will be coerced to a number. If it is not a legal port, a TypeError will be thrown.

On an error, err is an Error object, where err.code is the error code.

const dns = require('dns');
dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
  console.log(hostname, service);
  // Prints: localhost ssh
});

If this method is invoked as its util.promisify()ed version, it returns a Promise for an Object with hostname and service properties.