Scan list of systems on specific subnet for your script execution
Following code snippets allows you to create a map of connected devices on subnet.
import java.net.InetAddress;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
public class Jackychan {
public static void main(String[] args) throws UnknownHostException, IOException {
Map
getConnectedDevices = checkHosts(“127.0.0”);
System.out.println(getConnectedDevices.toString());
}
public static Map
Map
int timeout = 1000;
for (int i = 1; i < 255; i++) {
String host = subnet + "." + i;
if (InetAddress.getByName(host).isReachable(timeout)) {
connectedDevice.put(host, "is reachable");
}
}
return connectedDevice;
}
}
Output:
-------
{127.0.0.42=is reachable, 127.0.0.43=is reachable, ...... }
0 comments