Results 1 to 5 of 5
- 12-15-2015, 10:15 AM #1
Member
- Join Date
- Dec 2015
- Posts
- 3
- Rep Power
- 0
How to get List of All computers in the same network
Hey All,
I am working on a project in which i have to create a java application on having the information of devices in the same network.
I just want to find the IP address and Computer names.
Here i've found some code online and do some editing. but, does this appropriate to be used to check on all connected devices in the same network? or are there better way to do it?
Thanks & Regard
Stiln D
Java Code:package pinger; import java.io.IOException; import java.net.InetAddress; public class NetworkPing { 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"); //} } //System.out.println("End of searching"); } }
- 12-15-2015, 11:39 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: How to get List of All computers in the same network
Please don't post the same question multiple times.
I'll leave this one her, as it has a better title that "Hellp", and close the other one.Please do not ask for code as refusal often offends.
** This space for rent **
- 12-16-2015, 02:39 AM #3
Member
- Join Date
- Dec 2015
- Posts
- 3
- Rep Power
- 0
- 12-16-2015, 05:42 PM #4
Senior Member
- Join Date
- Mar 2013
- Location
- Greece
- Posts
- 183
- Rep Power
- 8
Re: How to get List of All computers in the same network
If am not wrong I believe that this is not going to work.. Because each machine may have different firewall rules so in some cases you will not be able to check if a computer is reachable or not cause a ping message could be restricted by firewall.
Secondly the 'address.isReachable(1000)' command is not safe enough cause a value like 1000 for a computer 'X' may be enough and for some others not but this depends on Internet speed i guess.
I believe the safest way to detect if a computer is reachable on a LAN network is to use the PING command through java Runtime.getRuntime().exec(command); and check the results (package lost etc).
- 12-16-2015, 06:12 PM #5
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: How to get List of All computers in the same network
Okay, here is the scoop. First, the standard Java IP package is not very good because:
1. You can't send raw IP packets which you construct.
2. You can't send homegrown ICMP packets via the normal Java packet protocols. (At least based on my previous perusal
it didn't appear you could).
So you could use a third party package that lets you construct and process ICMP echo and echo reply packets to do a ping in java. But then you may
have the afforementioned firewall problem. So go ahead and try and ping your hosts as best you can. Then check your local ARP table
to see what mappings of IP to mac addresses exist. These are created dynamically to resolve LAN addresses.
Since the ARP table can last longer than a host, you may want to clear it first and then do the pings. You might try using a broadcast ping. I used to do this on Sun workstations when I worked as a network engineer. I would then get back numerous replies. Note that the hosts must respond even with a firewall because the packet may be legitimate (they have to see it to reject it).
Then check you newly created ARP table. In an MSDOS window, try the arp command to see the table. Also ARP stands for Address Resolution protocol. Also note that I do not know how to retrieve a local arp table via Java. You may have to execute an external command to do this.
EDIT: I use Windows hence the MSDOS statement. For Unix and its variants, any command window should suffice.
Regards,
JimLast edited by jim829; 12-16-2015 at 06:27 PM.
The JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
Helpp
By stiln in forum NetworkingReplies: 0Last Post: 12-15-2015, 09:48 AM -
Help needed!!!!! choosing network computers
By apoorv in forum NetworkingReplies: 6Last Post: 03-22-2011, 06:33 PM -
How do i get a list of SQL Servers from network?
By flyto9 in forum NetworkingReplies: 0Last Post: 03-16-2011, 06:13 PM -
How to list all computer in a network?
By CaptnCAPSLOCK in forum NetworkingReplies: 1Last Post: 01-24-2011, 02:12 PM -
Sockets for computers in wireless network
By etrynus in forum NetworkingReplies: 2Last Post: 12-03-2008, 12:39 AM
Bookmarks