Two Laptop Bag*
The moose likes Sockets and Internet Protocols and the fly likes Determining computers on a network... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Determining computers on a network..." Watch "Determining computers on a network..." New topic
Author

Determining computers on a network...

Bill White
Ranch Hand

Joined: Oct 27, 2002
Posts: 82
I have posted this question in other topics here but have had no luck.
So, does anyone here know if its even possible for a Pure Java application, using TCP/IP to snoop out and find the other computers on a company LAN. I am not talking about anything fancy here, like finding computers on a company WAN, A company global wide netwok etc... I just want to be able to find the other machines on a local LAN.
Is there a limitation in JAVA for this? I was thinking about using JNDI but even that seems to fall short.
Please help. Thank You.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Bill,

So, does anyone here know if its even possible for a Pure Java application, using TCP/IP to snoop out and find the other computers on a company LAN.

Well, that depends on several things. I'm not sure that there is a 100% guaranteed way to enumerate all the machines on a LAN, but there are methods you could try. The best approach is to utilize a ping sweep. Now, without native code or running an external process like fping and capturing and parsing the output, you can't do that in Java because ICMP echo packets have to be sent over raw sockets. Another approach is to scan known ports on the LAN's subnet, eg ports 137-139 for Windows netsesion or some flavor of Unix running Samba, any machine on which you get an exception on you assume does not exist.
The main problem with this is some or all machines on the LAN may have these ports closed for security reasons. Even the ping sweep may not work if there is packet filtering software like ZoneAlarm installed on some or all of the machines.
There is a Java extension named JPcap with which you could code your own Java ping sweeper. It is a small package and seems to work OK but the documentation is attrocious. So you'll need a fair understanding of network protocols to use it effectively. You can get it here:
JPCap
If your machine is a Windows box, then you will also need WinPcap. You can get that here:
WinPcap
Hope this helps,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Bill White
Ranch Hand

Joined: Oct 27, 2002
Posts: 82
Micheal,
Thank you so VERY much for this response. It is very informative and I am sure will go a long way in helping me succeeding with this next project.
mahmoud adel
Greenhorn

Joined: May 10, 2009
Posts: 4
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.Arrays;
import java.io.IOException;
import java.io.*;
import java.util.Scanner;
import jpcap.*;
import jpcap.packet.*;

public class ARP{
public static void main(String[] args) throws IOException{

//Obtain the list of network interfaces
NetworkInterface[] devices = JpcapCaptor.getDeviceList();

//for each network interface
for (int i = 0; i < devices.length; i++) {
//print out its name and description
System.out.println(i+": "+devices[i].name + "(" + devices[i].description+")");

//print out its datalink name and description
System.out.println(" datalink: "+devices[i].datalink_name + "(" + devices[i].datalink_description+")");

//print out its MAC address
System.out.print(" MAC address:");
for (byte b : devices[i].mac_address)
System.out.print(Integer.toHexString(b&0xff) + ":");
System.out.println();

//print out its IP address, subnet mask and broadcast address
for (NetworkInterfaceAddress a : devices[i].addresses)
System.out.println(" address:"+a.address + " " + a.subnet + " "+ a.broadcast);
}

//NetworkInterface[] devices = JpcapCaptor.getDeviceList();
int index =1; // set index of the interface that you want to open.

//Open an interface with openDevice(NetworkInterface intrface, int snaplen, boolean promics, int to_ms)
final JpcapCaptor captor=JpcapCaptor.openDevice(devices[index], 65535, false, 20);









//JpcapCaptor captor=JpcapCaptor.openDevice(device[1], 65535, false, 20);

//call processPacket() to let Jpcap call PacketPrinter.receivePacket() for every packet capture.
//captor.processPacket(10,new PacketPrinter());
//System.out.println(packet);
//captor.close();

}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Determining computers on a network...
 
Similar Threads
Client Authentication(How to limit the computer to access to j2ee application)
Java Networking
Finding the computers that are on a network
want to run my swing application on local area network?
networkiing doubt