Friday, August 28, 2009

Retrieve list of Local Interfaces on a machine using Java

package com.anuj.utils;

import java.net.*;
import java.util.*;

public class InterfaceLister {
    public static void main(String[] args) throws SocketException {        
        Enumeration enu = NetworkInterface.getNetworkInterfaces();
        while (enu.hasMoreElements()) {
            NetworkInterface net = (NetworkInterface) enu.nextElement();
            System.out.println(net);
        }
    }
}

Output :
name:lo (Software Loopback Interface 1)
name:net0 (WAN Miniport (L2TP))
name:net1 (WAN Miniport (PPTP))
name:ppp0 (WAN Miniport (PPPOE))
name:eth0 (WAN Miniport (IPv6))
name:eth1 (WAN Miniport (IP))
name:ppp1 (RAS Async Adapter)
name:net2 (Broadcom 802.11b/g WLAN)
name:net3 (isatap.{737557E8-2B87-4532-A92B-EA6B83A827CD})
name:net4 (Teredo Tunneling Pseudo-Interface)
name:eth2 (WAN Miniport (IPv6)-QoS Packet Scheduler-0000)
name:eth3 (WAN Miniport (IP)-QoS Packet Scheduler-0000)
name:net5 (Broadcom 802.11b/g WLAN-QoS Packet Scheduler-0000)
name:net6 (Broadcom 802.11b/g WLAN-Native WiFi Filter Driver-0000)


Author : Anuj Patel
Blog : http://goldenpackagebyanuj.blogspot.in/