在表示 IPv6 地址的 IPAddress
实例上调用 ToString()
方法,我得到一些在地址后面带有百分号的文本。这是not documented 。这是什么意思?
返回值如下所示:fe80::1538:3f6c:a202:3af7%3
最佳答案
您的地址是范围内的文字 IPv6 地址
,
在维基百科页面中按 % 字符搜索:https://en.wikipedia.org/wiki/IPv6_address
在此处粘贴相关段落:
Scoped literal IPv6 addresses
For addresses with other than global scope (as described below), and in particular for link-local addresses, the choice of the network interface for sending a packet may depend on which zone the address belongs to: the same address may be valid in different zones, and be in use by a different host in each of those zones. Even if a single address is not in use in different zones, the address prefixes for addresses in those zones may still be identical, which makes the operating system unable to select an outgoing interface based on the information in the routing table (which is prefix-based).
In order to resolve the ambiguity in textual addresses, a zone index must be appended to the address, the two separated by a percent sign (%).[10] The syntax of zone indices is an implementation-dependent string, although numeric zone indices must be universally supported as well. The link-local address
fe80::1ff:fe23:4567:890a could be expressed by
fe80::1ff:fe23:4567:890a%eth2 or:
fe80::1ff:fe23:4567:890a%3
关于c# - IPAddress.ToString 中的地址后面的百分号是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58751009/