20
Dec

Discovering systems up and running on a subnet

This example is crude form of discovering all systems up and running (at time of execution) to run discovery of subnet.

============

package testCases;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class ipAddressHostname {

public static void main(String[] args) throws UnknownHostException, IOException {
checkHosts(“192.168.155”);

}

public static void checkHosts(String subnet) throws UnknownHostException, IOException {
int timeout = 1000;
for (int i = 1; i < 255; i++) {
String host = subnet + “.” + i;
if (InetAddress.getByName(host).isReachable(timeout)) {
System.out.println(host + ” is reachable”);
}
}
}

}

 

Output:

192.168.155.95 is reachable
192.168.155.96 is reachable
….