Why request.getRemoteAddr() returns ipv4 or ipv6 depending on context (post query or ajax query)

折月煮酒 提交于 2019-12-02 16:19:11

You can fix it by starting your server with this flag

-Djava.net.preferIPv4Stack=true

The reason is that the name you type in your browser has both ipv4 and ipv6 addresses. Browser chooses to use ipv4, flash chooses to use ipv6. There is nothing you can do about that on the server side (there is no way to convert).
However, you can change your DNS and make your name have only one address, either ipv4 or ipv6. You can also connect with a literal IP address (127.0.0.1), not a name (localhost).

you get an IPv6 address then IPv6 is being used. IPv4 and IPv6 are different protocols, and the client chooses which one to use when both are available.

If you want the client's IPv4 address then you can force them to use it by not advertising the IPv6 address in DNS. That would be a bad idea though with the increasing deployment of IPv6. Supporting both is good, so it is better to deal with clients using IPv6.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!