Hi, I want the program which will explain me the methods to find out the total number of list of local interfaces which are available on a particular machine. If you have knowledge then please help me.
Hi, I want the program which will explain me the methods to find out the total number of list of local interfaces which are available on a particular machine. If you have knowledge then please help me.
Hi, for getting the list of local interfaces on a machine you need to use getNetworkInterfaces() method of java. And the program of this will be as follows:
Code:import java.net.*; import java.util.*; public class Interfaced { public static void main(String[] args) throws Exception { Enumeration enum = NetworkInterface.getNetworkInterfaces(); while (enum.hasMoreElements()) { NetworkInterface network = (NetworkInterface) enum.nextElement(); System.out.println(network); } } }
Hi, you can use the following code to get list of Local Interfaces on a machine. Use it.
Code:import java.net.*; import java.util.*; public class Linterface { public Linterface() { try { Enumeration enum = NetworkInterface.getNetworkInterfaces(); InetAddress iadd = InetAddress.getLocalHost(); System.out.println("\nMachine Name : " + iadd.getHostName()); System.out.println("Machine IP Address : " + iadd.getHostAddress()); if(enum != null) { System.out.println("Local Interfaces "); while(enum.hasMoreElements()) { NetworkInterface localIf = (NetworkInterface)(enum.nextElement()); System.out.println("Interface Name : " + localIf.getName()); Enumeration ifAddrEnum = localIf.getInetAddresses(); System.out.print("IP Addresses : "); while(ifAddrEnum.hasMoreElements()) { InetAddress ifAddr = (InetAddress)(ifAddrEnum.nextElement()); System.out.print(ifAddr.toString() + " "); } } } else { System.out.println("No Local network interfaces were found"); } } catch(Exception e) { System.out.println ("Error : " + e); } } public static void main(String[] args) { Linterface localIf = new Linterface(); } }
Hi, I am beginner in java and don't know what you are wanted to know, but if you are able to get the solution about this then give me that solution. So, that I am also able to know some new things to improve my knowledge. So, if anyone has the solution about this, please give that to me. I am also waiting for your reply.
Bookmarks