Class NetUtils

java.lang.Object
org.apache.dubbo.common.utils.NetUtils

public final class NetUtils extends Object
IP and Port Helper for RPC
  • 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

      public static boolean isValidAddress(String address)
      Tells whether the address to test is an invalid address.
      Parameters:
      address - address to test
      Returns:
      true if invalid
    • 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()
    • getLocalHostV6

      public static String getLocalHostV6()
    • filterLocalHost

      public static String filterLocalHost(String host)
    • getIpByConfig

      public static String getIpByConfig(ScopeModel scopeModel)
    • getLocalAddress

      public static InetAddress getLocalAddress()
      Find first valid IP from local network card
      Returns:
      first valid local IP
    • getLocalAddressV6

      public static Inet6Address getLocalAddressV6()
    • isPreferredNetworkInterface

      public static boolean isPreferredNetworkInterface(NetworkInterface networkInterface)
      Is preferred NetworkInterface or not
      Parameters:
      networkInterface - NetworkInterface
      Returns:
      if the name of the specified NetworkInterface matches the property value from CommonConstants.DubboProperty.DUBBO_PREFERRED_NETWORK_INTERFACE, return true, or false
    • findNetworkInterface

      public static NetworkInterface findNetworkInterface()
      Get the suitable NetworkInterface
      Returns:
      If no NetworkInterface is available , return null
      Since:
      2.7.6
    • getHostName

      public static String getHostName(String address)
    • getLocalHostName

      public static String getLocalHostName()
    • getIpByHost

      public static String getIpByHost(String hostName)
      Parameters:
      hostName -
      Returns:
      ip address or hostName if UnknownHostException
    • toAddressString

      public static String toAddressString(InetSocketAddress address)
    • toAddress

      public static InetSocketAddress toAddress(String address)
    • toURL

      public static String toURL(String protocol, String host, int port, String path)
    • 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

      public static boolean matchIpExpression(String pattern, String address) throws UnknownHostException
      Check if address matches with specified pattern, currently only supports ipv4, use
      invalid @link
      {@link this#matchIpExpression(String, String, int)
      } for ipv6 addresses.
      Parameters:
      pattern - cird pattern
      address - '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

      public static boolean isMulticastAddress(String host)
      is multicast address or not
      Parameters:
      host - ipv4 address
      Returns:
      true if is multicast address
    • isIPV6URLStdFormat

      public static boolean isIPV6URLStdFormat(String ip)
    • getLegalIP

      public static String getLegalIP(String ip)