Results 1 to 4 of 4

Thread: How to get list of Local Interfaces on a machine?

  1. #1
    Join Date
    Nov 2009
    Posts
    1,340

    How to get list of Local Interfaces on a machine?

    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.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to get list of Local Interfaces on a machine?

    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);               
        }
     }
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to get list of Local Interfaces on a machine?

    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();
           }
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to get list of Local Interfaces on a machine?

    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.

Similar Threads

  1. Replies: 4
    Last Post: 07-04-2010, 01:11 PM
  2. Unable to load java virtual machine on local computer
    By Cadallic in forum Software Development
    Replies: 3
    Last Post: 11-09-2009, 01:05 PM
  3. Check if process is running on Local Machine using VB script
    By Aspen in forum Software Development
    Replies: 3
    Last Post: 03-09-2009, 09:46 PM
  4. SSH connection to a local Virtual Machine
    By deoWo in forum Networking & Security
    Replies: 6
    Last Post: 06-05-2009, 11:38 AM
  5. List users in local administrators group on remote machine
    By Nick in forum Windows Server Help
    Replies: 5
    Last Post: 11-10-2008, 12:31 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,574,978.73754 seconds with 17 queries