public final class NetUtils extends Object
| 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(ScopeModel scopeModel) |
static String |
getIpByHost(String hostName) |
static String |
getLegalIP(String ip) |
static InetAddress |
getLocalAddress()
Find first valid IP from local network card
|
static Inet6Address |
getLocalAddressV6() |
static String |
getLocalHost() |
static String |
getLocalHostName() |
static String |
getLocalHostV6() |
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)
Tells whether the port to test is an invalid port.
|
static boolean |
isIPV6URLStdFormat(String ip) |
static boolean |
isLocalHost(String host) |
static boolean |
isMulticastAddress(String host)
is multicast address or not
|
static boolean |
isPortInUsed(int port)
Check the port whether is in use in os
|
static boolean |
isPreferredNetworkInterface(NetworkInterface networkInterface)
Is preferred
NetworkInterface or not |
static boolean |
isValidAddress(String address)
Tells whether the address to test is an invalid address.
|
static boolean |
isValidLocalHost(String host) |
static void |
joinMulticastGroup(MulticastSocket multicastSocket,
InetAddress multicastAddress) |
static boolean |
matchIpExpression(String pattern,
String address)
Check if address matches with specified pattern, currently only supports ipv4, use
this#matchIpExpression(String, String, int) for ipv6 addresses. |
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 isPortInUsed(int port)
port - port to checkpublic static boolean isInvalidPort(int port)
port - port to testpublic static boolean isValidAddress(String address)
address - address to testpublic 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 getLocalHostV6()
public static String getIpByConfig(ScopeModel scopeModel)
public static InetAddress getLocalAddress()
public static Inet6Address getLocalAddressV6()
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 getLocalHostName()
public 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 address) throws UnknownHostException
this#matchIpExpression(String, String, int) for ipv6 addresses.pattern - cird patternaddress - 'ip:port'UnknownHostExceptionpublic 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 addresspublic static boolean isIPV6URLStdFormat(String ip)
Copyright © 2011–2020 The Apache Software Foundation. All rights reserved.