简体   繁体   中英

How to get local IP address of user connected through request - Nodejs

I have not been able to find any answer to this. I am looking for a way to obtain the local IP address of the user connected to my node server. I found the answer to find a way to get the user's public IP address, and was useful. I also need a way to determine which computer is connected, so the local IP as well through, possibly, something like this:

app.post('getip', function(req,res)
{
 var localIP  = req.headers['something or other'];
}

Thanks,

This should get you the IP in NodeJS if you're behind a proxy like nginx.

app.post('getip', function(req, res)
{
  var localIP  = req.headers["x-forwarded-for"];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM