How to get IPv6 Address in c#?

狂风中的少年 提交于 2019-12-06 22:57:00

问题


I use Request.UserHostAddress, can only get IPv4 address, how to get IPv6 address of a visitor?


回答1:


I assume you're talking about HttpRequest.UserHostAddress. It will always return the address that was used to connect to you. If the request was made over IPv6, it will return their IPv6 address; if the request was made over IPv4, it will return their IPv4 address.

You should start by investigating why the request is being made over IPv4. And the folks at http://serverfault.com will probably be of more help on that.




回答2:


An IPv4 address is translated to an IPv6 address by placing the 4 octets of the IPv4 address into the rightmost 4 octets of the IPv6 address.

After inserting the 4 octets of the IPv4 address into the rightmost 4 octets of the IPv6 address, the remaining left-most octets would be 0 in value.



来源:https://stackoverflow.com/questions/9103977/how-to-get-ipv6-address-in-c

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