Get name for network interface in Java
Description
The following code shows how to get name for network interface.
Example
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
//w w w. j av a 2 s . c o m
public class Main {
public static void main(String[] args) throws Exception {
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface ni = en.nextElement();
printParameter(ni);
}
}
public static void printParameter(NetworkInterface ni) throws SocketException {
System.out.println(" Name = " + ni.getName());
}
}
The code above generates the following result.