Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Sockets and Internet Protocols and the fly likes Listing Machines in a LAN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Listing Machines in a LAN" Watch "Listing Machines in a LAN" New topic

Listing Machines in a LAN

Prashant Sehgal
Ranch Hand

Joined: Jun 20, 2003
Posts: 56

I was going through the InetAddess/NetworkInterface family of classes and was wondering if it was possible to use the library to list all the machines in a LAN? I tried my hand at it and was not quite sure what to do. Anybody here tried anything like that?
Sushil Sharma

Joined: Nov 02, 2006
Posts: 22
The host on which your application runs, knows other hosts -- on same LAN -- via ARP protocol. And these IP addresses are not available to JVM.

The only way I can think is to get IP subnet address of your host, and try

for (all host addresses on the subnet) {
InetAddress inet = InetAddress.getByAddress(address);

Google to check if someone has written this type of utility.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19359

If it's a Windows network then possibly JCIFS could do that for you.
Prashant Sehgal
Ranch Hand

Joined: Jun 20, 2003
Posts: 56
Thanks guys. I will give these things a shot before I come back with more questions .
It is sorta covered in the JavaRanch Style Guide.
subject: Listing Machines in a LAN