类 NetUtils
- java.lang.Object
-
- org.apache.dubbo.common.utils.NetUtils
-
public class NetUtils extends Object
IP and Port Helper for RPC
-
-
构造器概要
构造器 构造器 说明 NetUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static String
filterLocalHost(String host)
static NetworkInterface
findNetworkInterface()
Get the suitableNetworkInterface
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 cardstatic 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 notstatic boolean
isPreferredNetworkInterface(NetworkInterface networkInterface)
Is preferredNetworkInterface
or notstatic 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)
-
-
-
方法详细资料
-
getRandomPort
public static int getRandomPort()
-
getAvailablePort
public static int getAvailablePort()
-
getAvailablePort
public static int getAvailablePort(int port)
-
isInvalidPort
public static boolean isInvalidPort(int port)
-
isValidAddress
public static boolean isValidAddress(String address)
-
isLocalHost
public static boolean isLocalHost(String host)
-
isAnyHost
public static boolean isAnyHost(String host)
-
isInvalidLocalHost
public static boolean isInvalidLocalHost(String host)
-
isValidLocalHost
public static boolean isValidLocalHost(String host)
-
getLocalSocketAddress
public static InetSocketAddress getLocalSocketAddress(String host, int port)
-
getLocalHost
public static String getLocalHost()
-
getIpByConfig
public static String getIpByConfig()
-
getLocalAddress
public static InetAddress getLocalAddress()
Find first valid IP from local network card- 返回:
- first valid local IP
-
isPreferredNetworkInterface
public static boolean isPreferredNetworkInterface(NetworkInterface networkInterface)
Is preferredNetworkInterface
or not- 参数:
networkInterface
-NetworkInterface
- 返回:
- if the name of the specified
NetworkInterface
matches the property value fromCommonConstants.DUBBO_PREFERRED_NETWORK_INTERFACE
, returntrue
, orfalse
-
findNetworkInterface
public static NetworkInterface findNetworkInterface()
Get the suitableNetworkInterface
- 返回:
- If no
NetworkInterface
is available , returnnull
- 从以下版本开始:
- 2.7.6
-
getIpByHost
public static String getIpByHost(String hostName)
- 参数:
hostName
-- 返回:
- ip address or hostName if UnknownHostException
-
toAddressString
public static String toAddressString(InetSocketAddress address)
-
toAddress
public static InetSocketAddress toAddress(String address)
-
joinMulticastGroup
public static void joinMulticastGroup(MulticastSocket multicastSocket, InetAddress multicastAddress) throws IOException
- 抛出:
IOException
-
setInterface
public static void setInterface(MulticastSocket multicastSocket, boolean preferIpv6) throws IOException
- 抛出:
IOException
-
matchIpExpression
public static boolean matchIpExpression(String pattern, String host, int port) throws UnknownHostException
-
matchIpRange
public static boolean matchIpRange(String pattern, String host, int port) throws UnknownHostException
- 参数:
pattern
-host
-port
-- 返回:
- 抛出:
UnknownHostException
-
isMulticastAddress
public static boolean isMulticastAddress(String host)
is multicast address or not- 参数:
host
- ipv4 address- 返回:
true
if is multicast address
-
-