Check if network interface is up in Java
Description
The following code shows how to check if network interface is up.
Example
import java.net.NetworkInterface;
import java.util.Enumeration;
/* www. java2 s .c om*/
public class Main {
public static void main(String[] args) throws Exception {
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface ni = en.nextElement();
System.out.println(" Is up = " + ni.isUp());
}
}
}
The code above generates the following result.