Class IPv6

java.lang.Object
org.miaixz.bus.core.net.ip.IPv6

public class IPv6 extends Object
IPv6工具类
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • IPv6

      public IPv6()
  • Method Details

    • ipv6ToBigInteger

      public static BigInteger ipv6ToBigInteger(String ipv6Str)
      将IPv6地址字符串转为大整数
      Parameters:
      ipv6Str - 字符串
      Returns:
      大整数, 如发生异常返回 null
    • bigIntegerToIPv6

      public static String bigIntegerToIPv6(BigInteger bigInteger)
      将大整数转换成ipv6字符串
      Parameters:
      bigInteger - 大整数
      Returns:
      IPv6字符串, 如发生异常返回 null
    • localIps

      public static LinkedHashSet<String> localIps()
      获得本机的IPv6地址列表 返回的IP列表有序,按照系统设备顺序
      Returns:
      IP地址列表 LinkedHashSet
    • getLocalHostName

      public static String getLocalHostName()
      获取主机名称,一次获取会缓存名称 注意此方法会触发反向DNS解析,导致阻塞,阻塞时间取决于网络!
      Returns:
      主机名称
    • getLocalMacAddress

      public static String getLocalMacAddress()
      获得本机MAC地址,默认使用获取到的IPv6本地地址对应网卡
      Returns:
      本机MAC地址
    • getLocalHardwareAddress

      public static byte[] getLocalHardwareAddress()
      获得本机物理地址(IPv6网卡)
      Returns:
      本机物理地址
    • getLocalhost

      public static InetAddress getLocalhost()
      获取本机网卡IPv6地址,规则如下:
      • 必须非回路(loopback)地址、非局域网地址(siteLocal)、IPv6地址
      • 多网卡则返回第一个满足条件的地址
      • 如果无满足要求的地址,调用 InetAddress.getLocalHost() 获取地址

      此方法不会抛出异常,获取失败将返回null

      Returns:
      本机网卡IP地址,获取失败返回null
    • getLocalhostDirectly

      public static InetAddress getLocalhostDirectly()
      获取本机网卡IPv6地址,不使用缓存,规则如下:
      • 必须非回路(loopback)地址、非局域网地址(siteLocal)、IPv6地址
      • 多网卡则返回第一个满足条件的地址
      • 如果无满足要求的地址,调用 InetAddress.getLocalHost() 获取地址

      此方法不会抛出异常,获取失败将返回null

      Returns:
      本机网卡IP地址,获取失败返回null
    • normalizeV6Address

      public static InetAddress normalizeV6Address(Inet6Address address)
      规范IPv6地址,转换scope名称为scope data,如:
           fe80:0:0:0:894:aeec:f37d:23e1%en0
                         |
           fe80:0:0:0:894:aeec:f37d:23e1%5
       
      地址后的“%5” 叫做 scope data.
      Parameters:
      address - IPv6地址
      Returns:
      规范之后的IPv6地址,使用scope data