Results 1 to 1 of 1
-
Getting all the iterfaces available on a workstation
Sometimes one wishes to get all the interfaces on a machine. The code given below does exactly that.
Java Code:public class IPAdress { public void getInterfaces (){ try { Enumeration e = NetworkInterface.getNetworkInterfaces(); while(e.hasMoreElements()) { NetworkInterface netface = (NetworkInterface) e.nextElement(); System.out.println("Net interface: "+netface.getName()); Enumeration e2 = netface.getInetAddresses(); while (e2.hasMoreElements()){ InetAddress ip = (InetAddress) e2.nextElement(); System.out.println("IP address: "+ip.toString()); } } } catch (Exception e) { System.out.println ("e: " + e); } } public static void main(String[] args) { IPAdress ip = new IPAdress(); ip.getInterfaces(); } }


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks