views:

1057

answers:

4

Hi all,

I want to get all the systems connected in a LAN? Can anyone suggest me?

A: 

Why do you want them, and why must they be names? Not all systems have a name.

What kind of systems are you trying to enumerate?

If you're trying to locate nearby instances of your own application, use multicast UDP to create a discovery protocol.

If you're trying to locate some server which has its own protocol for that purpose, then use its one.

MarkR
A: 

Here is how you can get Host Name. The following sample shows how to get Host name for local Host. Similarly you can try for other systems.

public class GetComputerName { public static void main(String args[]) { try{ String computername=InetAddress.getLocalHost().getHostName(); System.out.println(computername); }catch (Exception e){ System.out.println("Exception caught ="+e.getMessage()); } } }

srikanthv
+2  A: 

The Package I used in Java to achieve this was called jcifs. Here is the link to the Library .

Please note, to identify a machine on a subnet you will need to ping all the avaliable Ip addresses on the subnet. From there you can do a reverse IP Address lookup to get the machines details.

From memory from the OSI the reason why you want to ping all the machines on the network is because ICMP is still the lowest layer on the OSI Model. Though you just cannot trust just using ICMP (ping) requests to all machines on the subnet. The reason for this is most Windows Machines to prevent fishing attacks will block that protocol. So instead, you need to take a two stage detection approach. First, broadcast over the SubNet Ip address with a ICMP ping request. From the ICMP ping request after waiting 1 second, proceed to perform a SMB connection to the non responding IP addresses. You will find that most people will have either a shared printer of Microsoft Network that will respond to a request under that port.

The alternative is to use a NetBios reverse name lookup, though it still involves spamming the IP address range of the subnet.

Hope this helps.

Chad
hi thanks for replying my mail,can i have some code how to use the Jcif classes and how to get the system names connected in lAN
Bharath
http://www.hipergate.org/docs/api/4.0.0/com/knowgate/jcifs/netbios/NbtAddress.htmlNbtAddress.getByName( ipAddress ).isActive()Please note, you will need to put create a thread for each .getByName because it will put the current thread to sleep while it waits for a response back. Or it will time out.
Chad
I am unable to get all the system names in lan using jcifs using threads.Can we get all the names by giving the single system ip address,how to use threads for each system name.Can i have code how to get all the system names which are in lan.Please help me out in this..
Bharath
A: 

If I was going to try to implement this in Java, I'd pick some unused TCP/IP port number and then try to open a socket to each IP address in the LAN's IP address range(s). You expect all the connection attempts to fail, but they should fail in different ways depending on the whether a machine is using the IP address. If an IP address is in use, you should get a "connection refused". If it is not in use, you should get a "no route to host" or "no route to network". A "connect timed out" may indicate that the host is fire-walled, or that was recently alive but is not alive at the moment.

Another approach (which I don't know is you can do from Java) is to send ARP requests for each of the IP addresses in the network address range and see what turns up in your machine's ARP cache.

And of course, you can try sending ICMP Ping messages, but they may be firewalled.

Once you have a list of live IP addresses, use DNS reverse lookup to find the corresponding DNS names. But beware that not all IP addresses are bound to DNS names.

However this is all a bit tenuous given that a lot of machines and networks use firewalls of various kinds, and these are wont to drop network messages or send misleading responses.

Stephen C