开发者

GetHostAddress() returns no IPv6, only IPv4

开发者 https://www.devze.com 2023-04-05 06:06 出处:网络
When using Dns.GetHostAd开发者_StackOverflow中文版dresses(\"fred\") it returns only IPv4 addresses in response. How to get the IPv6 addresses as well? Is there different method I shall use?

When using Dns.GetHostAd开发者_StackOverflow中文版dresses("fred") it returns only IPv4 addresses in response. How to get the IPv6 addresses as well? Is there different method I shall use?

Socket.OSSupportsIPv6 returns true and IPv6 connections work fine. The OS is Windows 2008 R2, .Net version is 3.5.


IPv6 still uses DNS to resolve addresses so in order for this to work you will need to add an IPv6 entry to your zone file for this domain name. It'll then resolve properly.

I suspect that Ping will fall back to IPv4 if an IPv6 is not available, not exactly what you'd hope once you've specified the '-6' flag.


In case anyone is still having this problem in 2021, the System.Net.Dns class has an undocumented behavior: it filters addresses it thinks are unreachable when your only IPv6 address besides loopback is link-local. This filtering is performed even if the domain name exclusively resolves to a v6 address (you can try with v6.localhost.ayra.ch), in which case an exception is thrown.

If you're located in an IPv4 only network but want the ability to resolve v6 addresses in .NET, you can cheat your way around this problem by manually assigning your device a custom IP. Assign your device the IPv6 address 2001:db8::1 with a prefix length of 32 and no default gateway. I haven't found anything that stopped working so far because of this, and .NET will now resolve IPv6.

Note that the suggested IPv6 address and range is reserved for use in documentations, which means you should never encounter this range on the internet at all. If you want to make sure your choice doesn't conflicts with the address of someone else that follows this instruction, I suggest you use your mac address for the last 3 address segments.

I made a page that generates these address either with your MAC or randomly: https://cable.ayra.ch/docmac/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号