Package org.apache.dubbo.common.utils
Class NetUtils
java.lang.Object
org.apache.dubbo.common.utils.NetUtils
IP and Port Helper for RPC
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringfilterLocalHost(String host) static NetworkInterfaceGet the suitableNetworkInterfacestatic intstatic intgetAvailablePort(int port) static StringgetHostName(String address) static StringgetIpByConfig(ScopeModel scopeModel) static StringgetIpByHost(String hostName) static StringgetLegalIP(String ip) static InetAddressFind first valid IP from local network cardstatic Inet6Addressstatic Stringstatic Stringstatic Stringstatic InetSocketAddressgetLocalSocketAddress(String host, int port) static intstatic booleanstatic booleanisInvalidLocalHost(String host) static booleanisInvalidPort(int port) Tells whether the port to test is an invalid port.static booleanstatic booleanisLocalHost(String host) static booleanisMulticastAddress(String host) is multicast address or notstatic booleanisPortInUsed(int port) Check the port whether is in use in osstatic booleanisPreferredNetworkInterface(NetworkInterface networkInterface) Is preferredNetworkInterfaceor notstatic booleanstatic booleanisValidAddress(String address) Tells whether the address to test is an invalid address.static booleanisValidLocalHost(String host) static voidjoinMulticastGroup(MulticastSocket multicastSocket, InetAddress multicastAddress) static booleanmatchIpExpression(String pattern, String address) Check if address matches with specified pattern, currently only supports ipv4, use} for ipv6 addresses.invalid @link
{@link this#matchIpExpression(String, String, int)static booleanmatchIpExpression(String pattern, String host, int port) static booleanmatchIpRange(String pattern, String host, int port) static voidsetInterface(MulticastSocket multicastSocket, boolean preferIpv6) static InetSocketAddressstatic StringtoAddressString(InetSocketAddress address) static String
-
Method Details
-
isReuseAddressSupported
public static boolean isReuseAddressSupported() -
getRandomPort
public static int getRandomPort() -
getAvailablePort
public static int getAvailablePort() -
getAvailablePort
public static int getAvailablePort(int port) -
isPortInUsed
public static boolean isPortInUsed(int port) Check the port whether is in use in os- Parameters:
port- port to check- Returns:
- true if it's occupied
-
isInvalidPort
public static boolean isInvalidPort(int port) Tells whether the port to test is an invalid port.- Parameters:
port- port to test- Returns:
- true if invalid
-
isValidAddress
Tells whether the address to test is an invalid address.- Parameters:
address- address to test- Returns:
- true if invalid
-
isLocalHost
-
isAnyHost
-
isInvalidLocalHost
-
isValidLocalHost
-
getLocalSocketAddress
-
getLocalHost
-
getLocalHostV6
-
filterLocalHost
-
getIpByConfig
-
getLocalAddress
Find first valid IP from local network card- Returns:
- first valid local IP
-
getLocalAddressV6
-
isPreferredNetworkInterface
Is preferredNetworkInterfaceor not- Parameters:
networkInterface-NetworkInterface- Returns:
- if the name of the specified
NetworkInterfacematches the property value fromCommonConstants.DubboProperty.DUBBO_PREFERRED_NETWORK_INTERFACE, returntrue, orfalse
-
findNetworkInterface
Get the suitableNetworkInterface- Returns:
- If no
NetworkInterfaceis available , returnnull - Since:
- 2.7.6
-
getHostName
-
getLocalHostName
-
getIpByHost
- Parameters:
hostName-- Returns:
- ip address or hostName if UnknownHostException
-
toAddressString
-
toAddress
-
toURL
-
joinMulticastGroup
public static void joinMulticastGroup(MulticastSocket multicastSocket, InetAddress multicastAddress) throws IOException - Throws:
IOException
-
setInterface
public static void setInterface(MulticastSocket multicastSocket, boolean preferIpv6) throws IOException - Throws:
IOException
-
matchIpExpression
Check if address matches with specified pattern, currently only supports ipv4, use} for ipv6 addresses.invalid @link
{@link this#matchIpExpression(String, String, int)- Parameters:
pattern- cird patternaddress- 'ip:port'- Returns:
- true if address matches with the pattern
- Throws:
UnknownHostException
-
matchIpExpression
public static boolean matchIpExpression(String pattern, String host, int port) throws UnknownHostException - Throws:
UnknownHostException
-
matchIpRange
public static boolean matchIpRange(String pattern, String host, int port) throws UnknownHostException - Parameters:
pattern-host-port-- Returns:
- Throws:
UnknownHostException
-
isMulticastAddress
is multicast address or not- Parameters:
host- ipv4 address- Returns:
trueif is multicast address
-
isIPV6URLStdFormat
-
getLegalIP
-