Tag: ipv4

如何将ipv6地址转换为nodejs expressjs中的ipv4地址?

NODEJS的请求对象提供了这个方法req.connection.remoteAddres来获取客户端的IP地址,但是它给出了IPV6格式的地址,我怎么把它转换成更可读的IPV4格式呢?

Node.js dns.resolve()与dns.lookup()

我需要在Node.js中查找给定的主机到其对应的IP。 似乎有两个原生的方法来做到这一点: > dns.resolve('google.com', (error, addresses) => { console.error(error); console.log(addresses); }); QueryReqWrap { bindingName: 'queryA', callback: { [Function: asyncCallback] immediately: true }, hostname: 'google.com', oncomplete: [Function: onresolve], domain: Domain { domain: null, _events: { error: [Function] }, _eventsCount: 1, _maxListeners: undefined, members: [] } } > null [ '216.58.194.174' ] 和: > dns.lookup('google.com', (error, address, […]