• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Execute Ping from Android App

mossy464

Lurker
Mar 6, 2012
6
1
Hi,

For a college project Im trying to get an ARM binary of netcat running on my droid. I have compiled this already and it is contained in the data/local/tmp folder on the device. The netcat commands also work correctly via adb shell.

However, im trying to execute commands from code, netcat wasnt working so I decided to start with a basic command like ping. My code below is an attempt to ping my laptop from the phone.

Again this worked from adb shell but doesnt seem to work from the code. I captured in wireshark and no packet came from the phone when the code was ran.

The code enters the try block and displays the toast message but it seems that the ping is not working.

Can anyone tell me why the ping is not working? Once I fix that part I can move onto other commands.

Also, I have tried the .waitFor command to wait for the command to run but this gives an error in eclipse before compiling.

Thanks

Code:
package com.maurice.netcat;

import java.io.IOException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class NetcatActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView text = new TextView(this);
    text.setText("Netcat");
    setContentView(text);

    try
    {
        String ping = "system/bin/ping -c 1 192.168.0.13";
        Runtime.getRuntime().exec(ping);
        Toast.makeText(getApplicationContext(), "In Netcat Section", Toast.LENGTH_SHORT).show();


    }


    catch(IOException e) {
        System.out.println("Error Executing Netcat");
        Toast.makeText(getApplicationContext(), "In Exception Section", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
}
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones