Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there any way to retrieve client ipv4 and ipv6 address from request object. #7456

Closed
ksushilmaurya opened this issue Jun 28, 2016 · 3 comments
Labels
http Issues or PRs related to the http subsystem. question Issues that look for answers.

Comments

@ksushilmaurya
Copy link

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 ?

@mscdex mscdex added question Issues that look for answers. http Issues or PRs related to the http subsystem. labels Jun 28, 2016
@mscdex
Copy link
Contributor

mscdex commented Jun 28, 2016

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.

@mscdex mscdex closed this as completed Jun 28, 2016
@ksushilmaurya
Copy link
Author

Hi mscdex

Thanks for reply

@rraallvv
Copy link

rraallvv commented Sep 9, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

3 participants