我是 Java 编程的新手。我需要一种使用 java 获取 Linux 中所有网络接口(interface)并将该信息存储在 Java Map
中的方法。我在 Google 中找到了很多如何以静态方式执行此操作的方法 - 只是如何获取 eth0
并显示信息。我的代码需要可移植 - 代码必须显示部署在具有 2 或 4 个网络端口的服务器上的配置。
我认为最好的方法是使用 Java Map
获取信息,然后再显示它。你能帮帮我吗?
祝福
最佳答案
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while(interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
// ...
}
Here's the documentation for NetworkInterface
.
下面是一些示例代码: http://java.dzone.com/news/network-interface-details-java
关于java - 如何在java中获取所有网络接口(interface)并将信息存储在Java Map中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11102108/