KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > util > GetNetworkInterfaces


1 package org.jgroups.util;
2
3 import java.net.InetAddress JavaDoc;
4 import java.net.NetworkInterface JavaDoc;
5 import java.net.SocketException JavaDoc;
6 import java.util.Enumeration JavaDoc;
7
8 /**
9  * 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 JavaDoc[] args) throws SocketException JavaDoc {
17         Enumeration JavaDoc en=NetworkInterface.getNetworkInterfaces();
18         while(en.hasMoreElements()) {
19             NetworkInterface JavaDoc i=(NetworkInterface JavaDoc)en.nextElement();
20             System.out.println(i.getName() + ':');
21             System.out.println(" \t" + i.getDisplayName());
22             for(Enumeration JavaDoc en2=i.getInetAddresses(); en2.hasMoreElements();) {
23                 InetAddress JavaDoc addr=(InetAddress JavaDoc)en2.nextElement();
24                 System.out.println(" \t" + addr + " (" + addr.getHostName() + ')');
25             }
26             System.out.println("---------------------");
27         }
28     }
29
30 }
31
Popular Tags