0

I'd like to ping clients of my mobile AP. This way I want to see if the client is really connected to my hotspot, since /proc/net/arp only refreshes, when I shut down my hotspot.

This is my AsyncTask:

    protected Boolean doInBackground(Object... arg0) {
    // TODO Auto-generated method stub
    try {
        InetAddress ip = (InetAddress) arg0[0];
        this.context = (Context) arg0[1];
        return connected =  ip.isReachable(5000);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}

@Override
protected void onPostExecute(Boolean result) {
    // TODO Auto-generated method stub
    super.onPostExecute(result);
    android.widget.Toast.makeText(this.context, String.valueOf(this.connected), android.widget.Toast.LENGTH_SHORT).show();

}

Is there a way to ping a client when your device is not rooted?

Wolfen
  • 380
  • 1
  • 5
  • 18

1 Answers1

0

Since you have an IP address, you can do this:

public static String ping(String _ip) {

    try {
        String command = "ping -c 10 " + _ip;
        Process p = null;
        p = Runtime.getRuntime().exec(command);
        int status = p.waitFor();
        InputStream input = p.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(input));
        StringBuffer buffer = new StringBuffer();
        String line = "";
        while ((line = in.readLine()) != null) {
            buffer.append(line);
            buffer.append("\n");
        }
        String bufferStr = buffer.toString();
        return bufferStr;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return null;
}
cska631
  • 1
  • 2