public static List<String> getAllHosts() throws IOException {
                List<String> hostAddresses = new ArrayList<String>();

                InetAddress localhost = InetAddress.getLocalHost();

                String ipAddress = localhost.getHostAddress();

                for (int lastOctet = 1; lastOctet <= 115; lastOctet++) {
                        String[] octets = ipAddress.split("\\.");

                        String neighborIpAddress = String.format("%s.%s.%s.%d", 
octets[0],
                                        octets[1], octets[2], lastOctet);

                        InetAddress address = 
InetAddress.getByName(neighborIpAddress);
                        if (address.isReachable(5000)) {
                                Log.w(TAG, neighborIpAddress.toString());
                                hostAddresses.add(neighborIpAddress.toString());
                        } else {
                                Log.w(TAG, "Host unreachable");
                        }
                }

                return hostAddresses;
        }

Here is my code where I am trying to ping all machines on my network
but this never works.. isReachable always returns false even for
machines that I am able to ping from my machine using ping command..

Please help..

Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to