Frank R.
Frank R.

Reputation: 1253

node.js http(s): get ip address of remote server

When I'm doing https.request({ host: 'domain.com', ... }), how can I get the actual IP address I'm connecting to?

Note that domain.com resolving to multiple IPs and I want to know exactly the IP I'm connecting to.

I tried to get it from socket.remoteAddress: req.on('socket', function(socket) { console.log(socket.remoteAddress) }), but it's undefined.

Upvotes: 3

Views: 2393

Answers (1)

Bartosz Czerwonka
Bartosz Czerwonka

Reputation: 1651

Try use res.connection.remoteAddress

like this:

var http = require('http');

http.get('http://www.google.com', function(res) {
    console.log(res.connection.remoteAddress);
});

Upvotes: 5

Related Questions