I'm developing an Android application, I have to discover each hosts in a WiFi network, I have implemented a function that "ping" all IP address between 1 and 255 of a certain network.
This solution it work perfectly, but there is a problem, the execution time.. Every time that i start my application I wait about 256 second, it too long, i can't wait this time.
This is my source code (i found this code on Stack, i modified the code to work in my condition):
public class ScanNetwork {
    ArrayList < String > hosts;
    int i;
    boolean finish = false;
    public ArrayList < String > ScanNetwork(String ipAddress) {
        hosts = new ArrayList < String > ();
        final String subnet = ipAddress.substring(0, ipAddress.lastIndexOf("."));
        for (i = 0; i < 256; i++) {
            String currentHost = subnet + "." + i;
            Process p1 = null;
            int returnVal = 0;
            try {
                p1 = Runtime.getRuntime().exec("ping -w 50 -c 1 " + currentHost);
                returnVal = p1.waitFor();
            } catch (IOException e) {
                System.out.println("Log: " + e.toString());
            } catch (InterruptedException e) {
                System.out.println("Log: " + e.toString());
            }
            boolean reachable = (returnVal == 0);
            if (reachable) {
                if (!hosts.contains(currentHost)) {
                    hosts.add(currentHost);
                    System.out.println(currentHost);
                }
            }
        }
        return hosts;
    }
}
This source code is perfect but the execution time is excessive, there are other way to obtain all the host in the network ?
How i can solve this problem ?