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());

Leave a Comment

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据