Package ej.net.util

Class NetUtil


  • public class NetUtil
    extends Object
    Utilitary functions about net.
    • Method Detail

      • getInterface

        public static NetworkInterface getInterface​(String interfaceName)
                                             throws IOException
        Checks if a specific network interface is found.
        Parameters:
        interfaceName - the interface name.
        Returns:
        the NetworkInterface, null if not found.
        Throws:
        IOException - if an IOException occurs.
      • getFirstHostAddress

        public static InetAddress getFirstHostAddress()
        Gets the the first host address of a valid (connected and not loopback) interface. This function does not ensure to provide the same InetAddress for two consecutive call if two interfaces are valid.
        Returns:
        the host address, null if none found.
        See Also:
        getFirstHostAddress(NetworkInterface)
      • getFirstHostAddress

        public static InetAddress getFirstHostAddress​(NetworkInterface iface)
        Gets the first host address of a valid (connected and not loopback) interface.
        Parameters:
        iface - the interface to gets the host address from, can be null.
        Returns:
        the host address, null if none found.
      • isValidInetAdress

        public static boolean isValidInetAdress​(InetAddress addr)
        Checks whether an IP is not loopback nor zero.
        Parameters:
        addr - the InetAddress address to check, can be null.
        Returns:
        true if the IP is valid.
      • isConnected

        public static boolean isConnected​(InetAddress address)
        Checks whether an InetAddress is connected to a network.
        Parameters:
        address - the address to check, can be null.
        Returns:
        true if the address has been initialized.