如何在节点的Axios调用中检索远程IP地址

我想在Node中进行axios调用时,获得parsing的远程URL的IP地址。 请参阅下面的***评论。 提前感谢!

axios.get('http://www.example.com') .then(function (response) { // *** How can I get the resolved IP address of www.example.com here }) .catch(function (error) { console.log(error); }); 

Axios会返回你的响应头和你的请求的主体,如果没有指定的话,你不能从头获得IP地址,但是你可以使用node.js`中的dns模块。

 const dns = require('dns'); dns.resolve4('archive.org', (err, addresses) => { if (err) throw err; console.log(`addresses: ${JSON.stringify(addresses)}`); });