Hi I am writing an application in node.js and I need the client ip address to identify from which client the hit came. I need both ipv4 and ipv6 adderess. Is there any way in node.js to get both addresses ?
These kinds of questions are better suited for the nodejs/help repo. This repo is for issues about node core itself.
The answer to your question though is that you use req.socket.address().address
to get the IP and req.socket.address().family
to get the address family ('IPv4'
or 'IPv6'
). You cannot get both types of addresses since in general all IP network connections are made using either one or the other type.
Hi mscdex
Thanks for reply
@mscdex I'm getting a different value that the one from here, why is that? I tried express with and w/o trust proxy
enabled.
Most helpful comment
These kinds of questions are better suited for the nodejs/help repo. This repo is for issues about node core itself.
The answer to your question though is that you use
req.socket.address().address
to get the IP andreq.socket.address().family
to get the address family ('IPv4'
or'IPv6'
). You cannot get both types of addresses since in general all IP network connections are made using either one or the other type.