0

I'm trying to get users IP addreses in node but it always return local IP, I used different packages like ipware, request-ip but result is the same. How can I get real IPs this is my code now

var requestIp = require('request-ip');
app.use(function(req, res, next) {
    ip = requestIp.getClientIp(req);
    next();
});
Mona
  • 31
  • 1
  • 1
  • 5
  • Have you read this [how-to-determine-a-users-ip-address-in-node](https://stackoverflow.com/questions/8107856/how-to-determine-a-users-ip-address-in-node), you can also go with nodejs own methods – U Rogel Nov 18 '17 at 09:42
  • What is the actual IP though? Isnt it localhost if your server is on your local machine? – Sello Mkantjwa Nov 18 '17 at 09:44
  • @cowCrazy yes I tryed this all methodes, but no result, can't imagine what is the problem – Mona Nov 18 '17 at 09:45
  • no my server is not on my local machine @SelloMkantjwa – Mona Nov 18 '17 at 09:48
  • @Mona oh ok. I see – Sello Mkantjwa Nov 18 '17 at 09:49
  • Is the server sitting behind a proxy? – Sello Mkantjwa Nov 18 '17 at 09:49
  • Is there a proxy in front of your server? Or is the client connecting directly to your server with no load balancer or proxy? – jfriend00 Nov 18 '17 at 09:50
  • Check this out https://stackoverflow.com/questions/8107856/how-to-determine-a-users-ip-address-in-node – Satpal Tanan Nov 18 '17 at 16:33
  • I'm running server behind a proxy @SelloMkantjwa – Mona Nov 20 '17 at 06:37
  • yes there is a proxy @jfriend00 – Mona Nov 20 '17 at 06:49
  • If you're running a proxy, then the connection your server sees is from the proxy, not from the client. You can ONLY know what the client IP is if the proxy adds the client IP address to a header so you can get it from there. You will have to consult your proxy documentation to find out if it already does that or if it can be configured to do so. For example, here's info about that for NGINX: https://webmasters.stackexchange.com/questions/105418/getting-ip-address-and-location-of-my-own-server-instead-of-visiting-users – jfriend00 Nov 20 '17 at 14:33

0 Answers0