IP address returning as IPV6 instead of IPV4

IP address returning as IPV6 instead of IPV4
0

#1

Hello all

This may seem trivial, but I can’t seem to figure out how to display the user’s ip address with IPV4 instead of IPV6.

I simply just have as:
var ip = req.ip

in my callback function.


#2

If the client connects to the IPv6 address of the server, then their ip is going to be an IPv6 address, and if they connect to the IPv4 address, then it will be IPv4. No exceptions. If you’re connecting to localhost, that usually resolves to ::1, which is why you’re seeing it that way.

Ideally, leave it as it is, because that’s correct behavior.


#3

When I try out with FCC’s sample project, it gives me IPv4 format though


#4

That’s because like most public websites, it’s listening on an IPv4 address, and every client connects to that. Your server has both IPv4 and IPv6 addresses (it at least has ::1 for localhost) so when you hit the IPv6 address, it gives you that as your connecting IP.

If it is localhost that’s giving you an IPv6 address back, try connecting to 127.0.0.1 and notice how the client IP goes back to IPv4


#5

Cool, thanks for the feedback.

So would this mean that if I deploy my project to heroku, would it display as IPv4?


#6

Thank you so much for sharing such a good information about IPV4. I also found that we can 192.168.l.l change password