Reputation: 1476
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.
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?
Best Wishes
Upvotes: 5
Views: 9496
Reputation: 140
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while(interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
// ...
}
Here's the documentation for NetworkInterface
.
Here is some example code: http://java.dzone.com/news/network-interface-details-java
Upvotes: 7