java - Java中IPv6地址的奇怪符号

标签 java network-programming ipv6

当我调用方法NetworkInterface.getInetAddresses()时,我得到以下字符串:

"fe80:0:0:0:f06c:31b8:cd17:5a44%5"

我想知道%5在这里意味着什么?没有这个 %5 是否可以获取 IPv6 地址?

最佳答案

这里解释一下:

Inet6Adress - Format

The general format for specifying the scope_id is the following:

*IPv6-address%scope_id*

The IPv6-address is a literal IPv6 address as described above. The scope_id refers to an interface on the local system, and it can be specified in two ways.

  1. As a numeric identifier. This must be a positive integer that identifies the particular interface and scope as understood by the system. Usually, the numeric values can be determined through administration tools on the system. Each interface may have multiple values, one for each scope. If the scope is unspecified, then the default value used is zero.

  2. As a string. This must be the exact string that is returned by NetworkInterface.getName() for the particular interface in question. When an Inet6Address is created in this way, the numeric scope-id is determined at the time the object is created by querying the relevant NetworkInterface.

Note also, that the numeric scope_id can be retrieved from Inet6Address instances returned from the NetworkInterface class. This can be used to find out the current scope ids configured on the system.

关于java - Java中IPv6地址的奇怪符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14569912/

相关文章:

java - 使用嵌入式 jetty 服务器运行 Web 应用程序 (WAR)

java - 将 IP 地址与子网掩码表相匹配......Java 中最好的方法是什么?

测试 - 无法在 Mac 上创建 IPv6 网络

c - 过滤掉 IPv6 多播地址范围

java - 构造函数中的依赖注入(inject)

java - Hibernate 子查询.exists

java - JTextPane 仅显示单行插入的组件

c - 如何在多线程 TCP 服务器中获取每个连接的客户端地址

haskell - 通过网络进行高效的二进制 I/O

ipv6 - 如何确定两个 IPv6 地址之间的相等性?