Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs ip address result ::1

I have a realy interesting problem. I have a web site and i want to get client ip address. I found some solition but none of them work. I am using nginx.

i am using expressjs

app.post("/api/test",(req, res)=>{
console.log(req.header('x-forwarded-for')) // result "::1"
console.log(req.connection.remoteAddress) // result "::1"
console.log(req.ip) // result "::1"
})

I try yo use 3 party freamwork but result same.

like image 213
Furkan Aydın Avatar asked Feb 14 '17 07:02

Furkan Aydın


People also ask

What does IP address :: 1 mean?

The simple answer is that: ::1 is the compressed format of IPV6 loopback address 0:0:0:0:0:0:0:1 . It is the equivalent of the IPV4 address 127.0. 0.1. Follow this answer to receive notifications. answered Dec 22, 2021 at 9:41.

How do you find IP address in Nodejs?

The easiest way to find your IP address in Node. js is to pull the client IP address from the incoming HTTP request object. If you are running Express in your Node app, this is very easy to do. Access the socket field of the Express request object, and then look up the remoteAddress property of that field.

What is FFFF in IP address?

::ffff: is a subnet prefix for IPv4 (32 bit) addresses that are placed inside an IPv6 (128 bit) space. IPv6 is broken into two parts, the subnet prefix, and the interface suffix. Each one is 64 bits long, or, 4 groups of 4 hexadecimal characters.


1 Answers

If you are working on localhost this is normal try logging this on server you will get the address of the user.

Or you might be running nginx or similar reverse proxy in front of your node server in this case you should set proper headers

for nginx you need this ones

proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

check herefor more info

like image 140
nikoss Avatar answered Sep 18 '22 09:09

nikoss