Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
789 B
3
Indexable
import java.net.*;
import java.util.*;

public class InterfaceLister {

    public static void main(String[] args) throws SocketException {

        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();

        while (interfaces.hasMoreElements()) {
            NetworkInterface ni = interfaces.nextElement();
            System.out.println("Interface: " + ni.getName());
            Enumeration<InetAddress> addresses = ni.getInetAddresses();
            while (addresses.hasMoreElements()) {
                InetAddress addr = addresses.nextElement();
                if (!addr.isLinkLocalAddress()) {
                    System.out.println("\tIP Address: " + addr.getHostAddress());
                }
            }
        }
    }
}