public class NetUtils extends Object
| Constructor and Description |
|---|
NetUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
filterLocalHost(String host) |
static NetworkInterface |
findNetworkInterface()
Get the suitable
NetworkInterface |
static int |
getAvailablePort() |
static int |
getAvailablePort(int port) |
static String |
getHostName(String address) |
static String |
getIpByConfig() |
static String |
getIpByHost(String hostName) |
static InetAddress |
getLocalAddress()
Find first valid IP from local network card
|
static String |
getLocalHost() |
static InetSocketAddress |
getLocalSocketAddress(String host,
int port) |
static int |
getRandomPort() |
static boolean |
isAnyHost(String host) |
static boolean |
isInvalidLocalHost(String host) |
static boolean |
isInvalidPort(int port) |
static boolean |
isLocalHost(String host) |
static boolean |
isMulticastAddress(String host)
is multicast address or not
|
static boolean |
isPreferredNetworkInterface(NetworkInterface networkInterface)
Is preferred
NetworkInterface or not |
static boolean |
isValidAddress(String address) |
static boolean |
isValidLocalHost(String host) |
static void |
joinMulticastGroup(MulticastSocket multicastSocket,
InetAddress multicastAddress) |
static boolean |
matchIpExpression(String pattern,
String host,
int port) |
static boolean |
matchIpRange(String pattern,
String host,
int port) |
static void |
setInterface(MulticastSocket multicastSocket,
boolean preferIpv6) |
static InetSocketAddress |
toAddress(String address) |
static String |
toAddressString(InetSocketAddress address) |
static String |
toURL(String protocol,
String host,
int port,
String path) |
public static int getRandomPort()
public static int getAvailablePort()
public static int getAvailablePort(int port)
public static boolean isInvalidPort(int port)
public static boolean isValidAddress(String address)
public static boolean isLocalHost(String host)
public static boolean isAnyHost(String host)
public static boolean isInvalidLocalHost(String host)
public static boolean isValidLocalHost(String host)
public static InetSocketAddress getLocalSocketAddress(String host, int port)
public static String getLocalHost()
public static String getIpByConfig()
public static InetAddress getLocalAddress()
public static boolean isPreferredNetworkInterface(NetworkInterface networkInterface)
NetworkInterface or notnetworkInterface - NetworkInterfaceNetworkInterface matches
the property value from CommonConstants.DUBBO_PREFERRED_NETWORK_INTERFACE, return true,
or falsepublic static NetworkInterface findNetworkInterface()
NetworkInterfaceNetworkInterface is available , return nullpublic static String getIpByHost(String hostName)
hostName - public static String toAddressString(InetSocketAddress address)
public static InetSocketAddress toAddress(String address)
public static void joinMulticastGroup(MulticastSocket multicastSocket, InetAddress multicastAddress) throws IOException
IOExceptionpublic static void setInterface(MulticastSocket multicastSocket, boolean preferIpv6) throws IOException
IOExceptionpublic static boolean matchIpExpression(String pattern, String host, int port) throws UnknownHostException
UnknownHostExceptionpublic static boolean matchIpRange(String pattern, String host, int port) throws UnknownHostException
pattern - host - port - UnknownHostExceptionpublic static boolean isMulticastAddress(String host)
host - ipv4 addresstrue if is multicast addressCopyright © 2011–2020 The Apache Software Foundation. All rights reserved.