当我调用方法NetworkInterface.getInetAddresses()
时,我得到以下字符串:
"fe80:0:0:0:f06c:31b8:cd17:5a44%5"
我想知道%5
在这里意味着什么?没有这个 %5
是否可以获取 IPv6 地址?
最佳答案
这里解释一下:
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.
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.
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/