public class NetUtils extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
checkIpPortAvailable(String ip,
int port)
检测某个 IP 端口是否可用
|
static NetworkInterface |
findNetworkInterface()
Get the suitable
NetworkInterface |
static <T> T |
first(Collection<T> values)
Take the first element from the specified collection
|
static InetAddress |
getLocalAddress()
Find first valid IP from local network card
|
static String |
getLocalHost()
获取本机 IP 地址
|
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 InetAddress getLocalAddress()
public static NetworkInterface findNetworkInterface()
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 © 2023. All rights reserved.