public class NetUtils extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
NetUtils.NetworkInterfaceChecker |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
checkIpPortAvailable(String ip,
int port)
检测某个 IP 端口是否可用
|
static NetworkInterface |
findNetworkInterface(NetUtils.NetworkInterfaceChecker networkInterfaceChecker)
Get the suitable
NetworkInterface |
static <T> T |
first(Collection<T> values)
Take the first element from the specified collection
|
static InetAddress |
getLocalAddress(NetUtils.NetworkInterfaceChecker networkInterfaceChecker)
Find first valid IP from local network card
|
static String |
getLocalHost()
获取本机 IP 地址
|
static String |
getLocalHost4Test()
隔离调用 scope,核心场景才能直接调用 getLocalHost,方便查看使用点
|
static String |
getLocalHostWithNetworkInterfaceChecker(NetUtils.NetworkInterfaceChecker networkInterfaceChecker) |
static int |
getRandomPort() |
static boolean |
isPreferredNetworkInterface(NetworkInterface networkInterface)
Is preferred
NetworkInterface or not |
static org.apache.commons.lang3.tuple.Pair<String,Integer> |
splitAddress2IpAndPort(String address) |
public static int getRandomPort()
public static boolean checkIpPortAvailable(String ip, int port)
ip - IPport - 端口public static String getLocalHost()
public static String getLocalHostWithNetworkInterfaceChecker(NetUtils.NetworkInterfaceChecker networkInterfaceChecker)
public static String getLocalHost4Test()
public static InetAddress getLocalAddress(NetUtils.NetworkInterfaceChecker networkInterfaceChecker)
public static NetworkInterface findNetworkInterface(NetUtils.NetworkInterfaceChecker networkInterfaceChecker)
NetworkInterfaceNetworkInterface is available , return nullpublic static <T> T first(Collection<T> values)
T - the type of element of collectionvalues - the collection objectnullpublic static boolean isPreferredNetworkInterface(NetworkInterface networkInterface)
NetworkInterface or notnetworkInterface - NetworkInterfaceNetworkInterface matches
the property value from PowerJobDKey.PREFERRED_NETWORK_INTERFACE, return true,
or falseCopyright © 2024. All rights reserved.