Java NetworkInterface list network interfaces

Description

Java NetworkInterface list network interfaces

import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class Main {
  public static void main(String[] args) {
    try {/*from w w w . j  a  va  2 s .  c  o  m*/
      Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
      while (e.hasMoreElements()) {
        NetworkInterface nif = e.nextElement();
        System.out.println(
            "Name: " + nif.getName() + ", Supports Multicast: " + nif.supportsMulticast() + ", isUp(): " + nif.isUp());
      }
    } catch (SocketException ex) {
      ex.printStackTrace();
    }

  }
}



PreviousNext

Related