Getting API/get http request caller IP address


I am using an HTTP GET request node to receive calls from a client application from users. unfortunately, I cannot find the ip of the users in the msg coming out of the HTTP GET node. I tried to use msg.req data, but could not get more than the server ip on which I host node-red (AWS EC2 Ubuntu). Is there anyway to get this information from another place?


query.serverip = msg.req.ip; -> my server external ip
query.remoteAddress = msg.req.socket.remoteAddress; -> my server external ip
query.localAddress = msg.req.socket.localAddress; -> my server internal ip

query.clientip = msg.req.headers['x-forwarded-for']; -> returns undefined

I presume you mean an http In node, not an http request node. Generally it is not possible to determine the IP of the original machine sending the request. Consider when you fetch a web page from the internet in your browser. Your IP address may be something like but that would be of no use to the server at the other end.

The reason you are getting the wrong IP is that you have a proxy between you and the client. So you are getting the ip of the proxy not the client.

I THINK the reason you aren't getting the right forwarded for is that you haven't told node-red to trust the proxy. See the settings.js file for the info on that. Alternatively, it could be that the proxy isn't setting the header but that seems unlikely.

Unfortunately, things can get MUCH more complex though :slight_smile: See node.js - Express.js: how to get remote client address - Stack Overflow for some additional headers and req entries that might contain a client address.

And on top of those, you might still not be able to get their public address if they are on a network that uses CG-NAT because then you will only see a shared address.

1 Like

Thanks Colin, yes you are right, http in

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.