public final class NetUtils extends Object
isAnyLocalAddress 通配符地址 IPv4的通配符地址是0.0.0.0 isLoopbackAddress 回环地址 IPv4的的范围是127.0.0.0 ~ 127.255.255.255 IPv6的是0:0:0:0:0:0:0:1,也可以简写成::1 isLinkLocalAddress 本地连接地址 IPv4的的范围是169.254.0.0 ~ 169.254.255.255 IPv6的前12位是FE8,其他的位可以是任意取值 isSiteLocalAddress 地区本地地址 IPv4的分为三段:10.0.0.0 ~ 10.255.255.255等 IPv6的地区本地地址的前12位是FEC,其他的位可以是任意取值 isMulticastAddress 广播地址 IPv4的范围是224.0.0.0 ~ 239.255.255.255 IPv6的第一个字节是FF,其他的字节可以是任意值 isMCGlobal 全球范围的广播地址 isMCLinkLocal 子网广播地址 isMCNodeLocal 本地接口广播地址 isMCOrgLocal 组织范围的广播地址 isMCSiteLocal 站点范围的广播地址 host address:host name、ip address
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
IGNORED_NETWORK_INTERFACE |
static String |
LOCAL_HOST_NAME |
static String |
LOCAL_IP_ADDRESS |
static String |
PREFERRED_NETWORK_INTERFACE |
| 构造器和说明 |
|---|
NetUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static int |
findAvailablePort() |
static int |
findAvailablePort(int startPort)
Returns this server available port
|
static NetworkInterface |
findValidNetworkInterface()
Get the suitable
NetworkInterface |
static String |
getHostAddress(String hostName)
Gets host address by host name
|
static String |
getHostName(String hostAddress)
Gets host name by host address
|
static String |
getLocalHost()
Find first valid IP from local network card
|
static boolean |
isAnyHost(String host) |
static boolean |
isAvailablePort(int port)
Check the port is available
|
static boolean |
isConnectableHostPort(String host,
int port,
int timeout)
Returns the hostname port is connectable.
|
static boolean |
isReachableHost(String host) |
static boolean |
isValidIpAddress(String ip) |
static boolean |
isValidIpv4Address(InetAddress address) |
static boolean |
isValidLocalHost(String host) |
public static boolean isConnectableHostPort(String host, int port, int timeout)
host - the hostport - the porttimeout - the timeout value to be used in milliseconds.true if connectablepublic static boolean isAvailablePort(int port)
port - 待测试端口public static boolean isValidIpAddress(String ip)
public static boolean isValidLocalHost(String host)
public static boolean isReachableHost(String host)
public static boolean isAnyHost(String host)
public static String getLocalHost()
public static String getHostName(String hostAddress)
hostAddress - the host addresspublic static String getHostAddress(String hostName)
hostName - the host namepublic static int findAvailablePort()
public static int findAvailablePort(int startPort)
throws IllegalStateException
startPort - the start portIllegalStateException - if not foundpublic static boolean isValidIpv4Address(InetAddress address)
public static NetworkInterface findValidNetworkInterface()
NetworkInterfaceNetworkInterface is available , return nullCopyright © 2024. All rights reserved.