简体   繁体   English

如何获取通过请求连接的用户的本地IP地址 - Nodejs

[英]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.我正在寻找一种方法来获取连接到我的节点服务器的用户的本地 IP 地址。 I found the answer to find a way to get the user's public IP address, and was useful.我找到了找到获取用户公共 IP 地址的方法的答案,并且很有用。 I also need a way to determine which computer is connected, so the local IP as well through, possibly, something like this:我还需要一种方法来确定连接了哪台计算机,因此本地 IP 也可能通过以下方式确定:

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.如果您使用像 nginx 这样的代理,这应该会为您提供 NodeJS 中的 IP。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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