gpt4 book ai didi

java - 是否有将 ipv6 地址 fd00::识别为本地/私有(private)的 java api?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:19:50 25 4
gpt4 key购买 nike

我正在寻找一个可以正确识别给定 IP 地址是私有(private)地址还是本地地址的 Java API。此代码似乎适用于大多数 ipv4/ipv6 地址:

    boolean isLocalIp = InetAddress.getByName(ipAddr).isSiteLocalAddress() ||
InetAddress.getByName(ipAddr).isLinkLocalAddress() ||
InetAddress.getByName(ipAddr).isLoopbackAddress() ;

特别是,它将“fec0::”标识为本地/私有(private)类型地址,但不将“fc00::”或“fd00::”等标识为本地/私有(private)类型地址。

查看此维基百科链接 https://en.wikipedia.org/wiki/Private_network#IPv6 :

The address block fc00::/7 is reserved by IANA for Unique Local Addresses (ULA).[2] They are unicast addresses, but contain a 40-bit random number in the routing prefix to prevent collisions when two private networks are interconnected. Despite being inherently local in usage, the IPv6 address scope of unique local addresses is global.

The first block defined is fd00::/8, designed for /48 routing blocks, in which users can create multiple subnets, as needed.

任何人都可以帮助解释这里是否存在错误假设(例如“fc00::”或“fd00::”应被识别为本地/私有(private) ipv6 地址)或者是否有其他一些 java api 将正确识别所有本地/私有(private) IP 地址?

感谢您的任何反馈/回答!

最佳答案

Can anyone help with explaining if there is some false assumption here (e.g. that "fc00::" or "fd00::" should be identified as a local/private ipv6 address)

这些 block 中的地址并不意味着路由到单个管理域之外,但术语“站点本地地址”的含义更为具体。这个现已弃用的术语特指 block fec0::/10。

block fc00::/7 中的地址是不保证全局唯一的“唯一本地地址”,但它们不是链路本地地址,因为它们被允许在不同的广播域之间路由。

or if there is some other java api that will correctly identify all local/private ip addresses?

我简要地查看了 InetAddress.isAnyLocalAddress(),但它的文档似乎与您尝试执行的操作不符。看起来标准库没有这样的方法可用。

关于java - 是否有将 ipv6 地址 fd00::识别为本地/私有(private)的 java api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53764109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com