JAVA 获取网卡信息

Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
    NetworkInterface networkInterface = networkInterfaces.nextElement();
    if (networkInterface.isLoopback() || networkInterface.isVirtual()) {
        continue;
    }
    System.out.println(ToStringBuilder.reflectionToString(networkInterface, ToStringStyle.MULTI_LINE_STYLE));
}

NetworkInterface en0 = NetworkInterface.getByName("en0");
System.out.println(ToStringBuilder.reflectionToString(en0));
System.out.println(en0.getInterfaceAddresses().get(1).getAddress().getHostAddress());