Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: How to get List of All computers in my network or Computers Connected to me.

  1. #1
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default How to get List of All computers in my network or Computers Connected to me.

    Hey All,
    I am working on a project in which i have to install client software through server to all clients and the server could be a linux machine.
    I just want to find the IP address and Computer names Connected to my system.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: How to get List of All computers in my network or Computers Connected to me.

    Hello DanBrown,

    Welcome to the Java Programming Forums.

    Take a look at this link.
    It will get the IP address and computer name of the local machine. I know its not what you need but its a place to start..

    http://www.javaprogrammingforums.com...p-address.html

    I will look into how we can get the details of machines connected to the server.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: How to get List of All computers in my network or Computers Connected to me.

    Quote Originally Posted by JavaPF View Post
    Hello DanBrown,

    Welcome to the Java Programming Forums.

    Take a look at this link.
    It will get the IP address and computer name of the local machine. I know its not what you need but its a place to start..

    http://www.javaprogrammingforums.com...p-address.html

    I will look into how we can get the details of machines connected to the server.
    this info is very useful.
    I would like to share some more details regarding my project.This is an client server architecture based project in this project we can install client software from server side, so i need to show all clients connected to the server.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  4. #4
    Junior Member
    Join Date
    Jan 2011
    Location
    Mumbai(INDIA)
    Posts
    1
    Thanks
    0
    Thanked 2 Times in 1 Post

    Smile Re: How to get List of All computers in my network or Computers Connected to me.

    Hi ,

    Try this code:


    InetAddress localhost = InetAddress.getLocalHost();
    // this code assumes IPv4 is used
    byte[] ip = localhost.getAddress();
    for (int i = 1; i <= 254; i++)
    {
    ip[3] = (byte)i;
    InetAddress address = InetAddress.getByAddress(ip);
    if (address.isReachable(1000))
    {
    // machine is turned on and can be pinged
    }
    else if (!address.getHostAddress().equals(address.getHostName())
    {
    // machine is known in a DNS lookup
    }
    else
    {
    // the host address and host name are equal, meaning the host name could not be resolved
    }
    }

  5. The Following 2 Users Say Thank You to Amar For This Useful Post:

    javapenguin (January 14th, 2011), JavaPF (January 12th, 2011)

  6. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: How to get List of All computers in my network or Computers Connected to me.

    I have expanded on Amar's code slightly. It does the job but would be nice to speed it up..

    import java.io.IOException;
    import java.net.InetAddress;
     
    public class NetworkPing {
     
    	/**
    	 * JavaProgrammingForums.com
    	 */
    	public static void main(String[] args) throws IOException {
     
    		InetAddress localhost = InetAddress.getLocalHost();
    		// this code assumes IPv4 is used
    		byte[] ip = localhost.getAddress();
     
    		for (int i = 1; i <= 254; i++)
    		{
    			ip[3] = (byte)i;
    			InetAddress address = InetAddress.getByAddress(ip);
    		if (address.isReachable(1000))
    		{
    			System.out.println(address + " machine is turned on and can be pinged");
    		}
    		else if (!address.getHostAddress().equals(address.getHostName()))
    		{
    			System.out.println(address + " machine is known in a DNS lookup");
    		}
    		else
    		{
    			System.out.println(address + " the host address and host name are equal, meaning the host name could not be resolved");
    		}
    		}
     
    	}
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  7. The Following 2 Users Say Thank You to JavaPF For This Useful Post:

    DanBrown (January 13th, 2011), javapenguin (January 14th, 2011)

  8. #6
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: How to get List of All computers in my network or Computers Connected to me.

    I have done the same thing thank u all.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  9. #7
    Junior Member
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Re: How to get List of All computers in my network or Computers Connected to me.

    Thank you, my boss assigned me such a task and i could do it fast.Thank u very much

Similar Threads

  1. Replies: 8
    Last Post: April 21st, 2013, 09:20 AM
  2. How to get your computer name and IP address?
    By JavaPF in forum Java Networking Tutorials
    Replies: 7
    Last Post: December 8th, 2011, 12:36 PM
  3. SpinnerListModel setList(List<?> list)
    By roy epperson in forum Collections and Generics
    Replies: 4
    Last Post: November 29th, 2010, 10:30 AM
  4. calling a java a class connected to derby from a batch file
    By Reem in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 31st, 2010, 04:01 PM
  5. Java program to open and close computer CD/DVD drive
    By JavaPF in forum Java Programming Tutorials
    Replies: 0
    Last Post: January 28th, 2009, 12:04 PM