is there any way to know the remote IP adress form a request on on the http server? Using "net" for a socket connection is socket.remoteAddress but for the http server I get undifined for the same .remoteAddress
Regards
You can use RemoteAddr to get the remote client's IP address and port (the format is "IP:port"), which is the address of the original requestor or the last proxy (for example a load balancer which lives in front of your server). This is all you have for sure. This is because internally http. Header.
The –r junction option allows you to insert client IP address information into the HTTP headers of requests destined for junctioned application servers. The HTTP header information enables applications on junctioned third-party servers to perform actions based on this IP address information.
REMOTE_HOST pertains to the hostname of the client (i.e. the computer making the request). REMOTE_ADDR refers to the IP address of the client. There would be times when the hostname is unresolvable so the REMOTE_HOST will return the REMOTE_ADDR or the IP address instead.
I'm just adding this because I came across this article and it still took me a little bit of time to figure out it was as you see in the following:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello ' + req.connection.remoteAddress + '!');
console.log("request received from: " + req.connection.remoteAddress);
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
You can use the request.connection
method to retrieve the net.Socket
object, where you can then use your socket.remoteAddress
property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With