public class NetUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.net.InetAddress |
getFirstHostAddress()
Gets the the first host address of a valid (connected and not loopback) interface.
|
static java.net.InetAddress |
getFirstHostAddress(java.net.NetworkInterface iface)
Gets the first host address of a valid (connected and not loopback) interface.
|
static java.net.NetworkInterface |
getInterface(java.lang.String interfaceName)
Checks if a specific network interface is found.
|
static boolean |
isConnected(java.net.InetAddress address)
Checks whether an
InetAddress is connected to a network. |
static boolean |
isValidInetAdress(java.net.InetAddress addr)
Checks whether an IP is not loopback nor zero.
|
public static java.net.NetworkInterface getInterface(java.lang.String interfaceName)
throws java.io.IOException
interfaceName - the interface name.NetworkInterface, null if not found.java.io.IOException - if an IOException occurs.public static java.net.InetAddress getFirstHostAddress()
InetAddress for two consecutive call if two interfaces are valid.null if none found.getFirstHostAddress(NetworkInterface)public static java.net.InetAddress getFirstHostAddress(java.net.NetworkInterface iface)
iface - the interface to gets the host address from, can be null.null if none found.public static boolean isValidInetAdress(java.net.InetAddress addr)
addr - the InetAddress address to check, can be null.true if the IP is valid.public static boolean isConnected(java.net.InetAddress address)
InetAddress is connected to a network.address - the address to check, can be null.true if the address has been initialized.