01: package org.jgroups.util;
02:
03: import java.net.InetAddress;
04: import java.net.NetworkInterface;
05: import java.net.SocketException;
06: import java.util.Enumeration;
07:
08: /**
09: * Lists all network interfaces on a system
10: * @author Bela Ban Dec 18
11: * @author 2003
12: * @version $Id: GetNetworkInterfaces.java,v 1.1 2005/06/23 13:31:09 belaban Exp $
13: */
14: public class GetNetworkInterfaces {
15:
16: public static void main(String[] args) throws SocketException {
17: Enumeration en = NetworkInterface.getNetworkInterfaces();
18: while (en.hasMoreElements()) {
19: NetworkInterface i = (NetworkInterface) en.nextElement();
20: System.out.println(i.getName() + ':');
21: System.out.println(" \t" + i.getDisplayName());
22: for (Enumeration en2 = i.getInetAddresses(); en2
23: .hasMoreElements();) {
24: InetAddress addr = (InetAddress) en2.nextElement();
25: System.out.println(" \t" + addr + " ("
26: + addr.getHostName() + ')');
27: }
28: System.out.println("---------------------");
29: }
30: }
31:
32: }
|