networking

how can i obtain the IPAddress of all computers in a network

There is not really a neat way to do this, as far as I know, but I suppose this would work:


InetAddress[] all = new InetAddress[256];
for(...)
  all[i] = InetAddress.getByName("x.y.z."+i);

// make this heavily multithreaded!!
boolean[] av = ...;
for(...)
   av[i] = all[i].isReachable(1000);

for(...)
  if(av[i])
   System.out.println("Found: "+all[i]);

I hope you can interpret this pseudocode :-*

You need to write it in native code (not java) - java doesn’t give you low-enough level access to the NIC hardware to do this kind of thing efficiently.

However, in 99% of cases you dont want what you asked for, you instead just want to know “which ip addresses are also running a copy of my app?”. In which case, just look at the javadocs for the “broadcast” parts of UDP.

NB: the 1% includes people writing viruses, which has long been used as the semi-official excuse for not providing lower-level decenta access. Pisses me off, because you can’t write really good, efficient, intelligent P2P cluster code like this. Grumble grumble :).

What BBB descriebs is sometimes referred to as “Discovery”.

I have an example of broadcast based discovery code in the networking chapter I wrote for Shawn Kendall’s java game programming book.