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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Execute Ping from Android App

  • 17-06-2013 1:44pm
    #1
    Registered Users, Registered Users 2 Posts: 1,146 ✭✭✭


    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,146 ✭✭✭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. :)


Advertisement