Package ej.net.util
Class NetUtil
- java.lang.Object
-
- ej.net.util.NetUtil
-
public class NetUtil extends Object
Utilitary functions about net.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static InetAddressgetFirstHostAddress()Gets the the first host address of a valid (connected and not loopback) interface.static InetAddressgetFirstHostAddress(NetworkInterface iface)Gets the first host address of a valid (connected and not loopback) interface.static NetworkInterfacegetInterface(String interfaceName)Checks if a specific network interface is found.static booleanisConnected(InetAddress address)Checks whether anInetAddressis connected to a network.static booleanisValidInetAdress(InetAddress addr)Checks whether an IP is not loopback nor zero.
-
-
-
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,nullif 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 sameInetAddressfor two consecutive call if two interfaces are valid.- Returns:
- the host address,
nullif 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 benull.- Returns:
- the host address,
nullif none found.
-
isValidInetAdress
public static boolean isValidInetAdress(InetAddress addr)
Checks whether an IP is not loopback nor zero.- Parameters:
addr- theInetAddressaddress to check, can benull.- Returns:
trueif the IP is valid.
-
isConnected
public static boolean isConnected(InetAddress address)
Checks whether anInetAddressis connected to a network.- Parameters:
address- the address to check, can benull.- Returns:
trueif the address has been initialized.
-
-