c# - IPAddress.ToString 中的地址后面的百分号是什么?

标签 c# .net networking

在表示 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/

相关文章:

c - ICMP header 和 IP header 校验和计算

c# - Vb.Net 的 with java 中的关键字?

c# - 序列化时不忽略在 DefaultValue 中声明的数组

.net - 我怎样才能提高我们的 .NET 生产力?

C#,奇怪的优化

linux - wget分析文件大小

c# - C#中如何跨线程调用BindingList<T>

c# - 可空 boolean 作为 C# 中的三态变量

c# - 通过 System.Data.Linq.DataContext 插入 SQL Server 时出错

networking - TCP 三向握手 - 搭载 ACK