Node: is there any way to retrieve client ipv4 and ipv6 address from request object.

Created on 28 Jun 2016  路  3Comments  路  Source: nodejs/node

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 ?

http question

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 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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willnwhite picture willnwhite  路  3Comments

jmichae3 picture jmichae3  路  3Comments

srl295 picture srl295  路  3Comments

danialkhansari picture danialkhansari  路  3Comments

mcollina picture mcollina  路  3Comments