public class Ipv6Util extends Object
Constructor and Description |
---|
Ipv6Util() |
Modifier and Type | Method and Description |
---|---|
static String |
bigIntegerToIPv6(BigInteger bigInteger)
将大整数转换成ipv6字符串
|
static byte[] |
getLocalHardwareAddress()
获得本机物理地址(IPv6网卡)
|
static InetAddress |
getLocalhost()
获取本机网卡IPv6地址,规则如下:
必须非回路(loopback)地址、非局域网地址(siteLocal)、IPv6地址
多网卡则返回第一个满足条件的地址
如果无满足要求的地址,调用
InetAddress.getLocalHost() 获取地址
此方法不会抛出异常,获取失败将返回null |
static InetAddress |
getLocalhostDirectly()
获取本机网卡IPv6地址,不使用缓存,规则如下:
必须非回路(loopback)地址、非局域网地址(siteLocal)、IPv6地址
多网卡则返回第一个满足条件的地址
如果无满足要求的地址,调用
InetAddress.getLocalHost() 获取地址
此方法不会抛出异常,获取失败将返回null 见:https://github.com/dromara/hutool/issues/428 |
static String |
getLocalHostName()
获取主机名称,一次获取会缓存名称
注意此方法会触发反向DNS解析,导致阻塞,阻塞时间取决于网络! |
static String |
getLocalMacAddress()
获得本机MAC地址,默认使用获取到的IPv6本地地址对应网卡
|
static BigInteger |
ipv6ToBigInteger(String ipv6Str)
将IPv6地址字符串转为大整数
|
static LinkedHashSet<String> |
localIps()
获得本机的IPv6地址列表
返回的IP列表有序,按照系统设备顺序 |
static InetAddress |
normalizeV6Address(Inet6Address address)
规范IPv6地址,转换scope名称为scope id,如:
fe80:0:0:0:894:aeec:f37d:23e1%en0
|
fe80:0:0:0:894:aeec:f37d:23e1%5
地址后的“%5” 叫做 scope id.
|
public static BigInteger ipv6ToBigInteger(String ipv6Str)
ipv6Str
- 字符串public static String bigIntegerToIPv6(BigInteger bigInteger)
bigInteger
- 大整数public static LinkedHashSet<String> localIps()
LinkedHashSet
public static String getLocalHostName()
public static String getLocalMacAddress()
public static byte[] getLocalHardwareAddress()
public static InetAddress getLocalhost()
InetAddress.getLocalHost()
获取地址
此方法不会抛出异常,获取失败将返回null
null
public static InetAddress getLocalhostDirectly()
InetAddress.getLocalHost()
获取地址
此方法不会抛出异常,获取失败将返回null
见:https://github.com/dromara/hutool/issues/428
null
public static InetAddress normalizeV6Address(Inet6Address address)
fe80:0:0:0:894:aeec:f37d:23e1%en0 | fe80:0:0:0:894:aeec:f37d:23e1%5
地址后的“%5” 叫做 scope id.
方法来自于Dubbo
address
- IPv6地址Copyright © 2025. All rights reserved.