Class NetworkUtil


  • public class NetworkUtil
    extends Object
    Author:
    Kir
    • Method Detail

      • getSelfAddresses

        @NotNull
        public static InetAddress[] getSelfAddresses​(@Nullable
                                                     Filter<InetAddress> filter)
                                              throws SocketException
        Returns all self addresses accepted by provided filter. IPv6 link local addresses are always ignored. Loopback address is ignored, unless it's the only one available address on current machine.
        Parameters:
        filter - address filter or null, if all addresses must be returned
        Returns:
        all addresses matched by filter
        Throws:
        SocketException - if socket exception occurs
      • isPortBusy

        public static boolean isPortBusy​(int port)
      • isPortBusy

        public static boolean isPortBusy​(int port,
                                         boolean showThreadDump)
      • isPortBusy

        public static boolean isPortBusy​(String host,
                                         int port,
                                         int connectTimeoutMsecs)
      • isPortBusy

        public static boolean isPortBusy​(String host,
                                         int port,
                                         int connectTimeoutMsecs,
                                         boolean showThreadDump)
      • getFreePort

        public static int getFreePort​(int i)
      • getHostAddressWithoutScope

        @NotNull
        public static String getHostAddressWithoutScope​(@NotNull
                                                        Inet6Address ipv6Address)
        Returns host address without scope id from provided IPv6 address. Scope id is required locally, but must not be used by client establishing connection to some IPv6 address.
        Parameters:
        ipv6Address - IPv6 address
        Returns:
        host address without scope id
      • isLocalHost

        public static boolean isLocalHost​(@NotNull
                                          String hostname)
        Checks whether supplied hostname belongs to the current host
        Parameters:
        hostname - the host name to check
        Returns:
        true, if hostname belongs to calling machine and false otherwise
      • hostAndPort

        public static String hostAndPort​(@NotNull
                                         String ipOrHost,
                                         @Nullable
                                         Integer portNumber)
        Forms a textual representation of a host:port address considering special ":" meaning in IPv6
        Since:
        2018.1