简体   繁体   中英

How to get domain name by IP Address and port in native NodeJS?

Which method is closest to desiredMethod in below code?

const dns = require("dns");

const IP_ADDRESS = "XX.XX.XXX.XXX"; // Any valid IP address
const PORT = 8080;

dns.deiredMethod(`${IP_ADDRESS}:${PORT}`, (error, domain) => {
   console.log(domain); // example output: "example.com"
})

Not quite sure if I understand correct what you try to achieve. But the native dns module of an Node.js installation allows to resolve hostnames by IP address and port using dns.lookupService(address, port, callback) . Please see Node.js DNS for details.

const dns = require("dns");

dns.lookupService('172.217.18.110', 22, (err, hostname, service) => {
    console.log(hostname, service);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM