Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.

Execute Ping from Android App

  • 17-06-2013 02:44PM
    #1
    Registered Users, Registered Users 2 Posts: 1,157
    ✭✭✭


    Hi All,

    Im trying to get an ARM binary of netcat running on my droid. Its already contained in the data/local/tmp folder on the device. The netcat commands also work 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 toast displays but no ping is sent. 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.

    Thanks


    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();
        }
    }
    }
    


Comments

  • Registered Users, Registered Users 2 Posts: 12 ryanfm


    Have you put <uses-permission android:name="android.permission.INTERNET"></uses-permission> in your manifest file ?

    Try pinging localhost.


  • Registered Users, Registered Users 2 Posts: 1,157 mossy464
    ✭✭✭


    ryanfm wrote: »
    Have you put <uses-permission android:name="android.permission.INTERNET"></uses-permission> in your manifest file ?

    Try pinging localhost.

    That did the trick. Thank you very much.

    My head has been wrecked for a few weeks on this, all over a simple omission of permissions. Anyway I'll know for future reference about adding permissions to the manifest file. :)


Welcome!

It looks like you're new here. Sign in or register to get started.
Advertisement