如何获取java中的所有网络接口并将信息存储在Java Map中 [英] How to get all network interfaces in java and store the information in Java Map
问题描述
我是Java编程的新手。我需要一种方法来使用java获取Linux中的所有网络接口,并将该信息存储在Java Map
中。我在Google中找到了许多以静态方式执行此操作的方法 - 只需如何获取 eth0
并显示信息。我的代码需要是可移植的 - 代码必须显示部署在具有2或4个网络端口的服务器上的配置。
I'm new to Java programming. I need a way to get all network interfaces in Linux using java and store that information in Java Map
. I found many ways in Google how to do this in a static way - just how to get eth0
and display the information. My code needs to be portable - the code must display the configuration deployed on server with 2 or 4 network ports.
我认为最好的方法是使用Java Map
获取信息,然后再显示它。你能帮帮我吗?
I thing that the best way to do this is to use Java Map
to get the information and then later on display it. Would you please help me?
祝福
推荐答案
`
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements())
{
NetworkInterface networkInterface = interfaces.nextElement();
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
}
}
`
看看NetworkInterface,InterfaceInfo
Take a look at NetworkInterface, InterfaceInfo
这里有更多细节:
http://java.dzone.com/news/network-interface-details-java
这篇关于如何获取java中的所有网络接口并将信息存储在Java Map中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!