2

i'm trying to create an app android to run nmap commands from terminal and shows the result in the app

I am trying to run this line of code:

try {
    Process p = Runtime.getRuntime().exec("nmap  ");           
    BufferedReader inputStream = new BufferedReader(new InputStreamReader(p.getInputStream()));

    String s;
    // reading output stream of the command  
    while ((s = inputStream.readLine()) != null) {
        Log.d("res", s);
    }
 } catch (Exception e) {
       e.printStackTrace();
 }

W/System.err: java.io.IOException: Cannot run program "nmap": error=13, Permission denied

Shankha057
  • 1,296
  • 1
  • 20
  • 38
Rachid
  • 39
  • 3
  • Possible duplicate of [execute shell command from android](https://stackoverflow.com/questions/20932102/execute-shell-command-from-android) – Shankha057 Nov 08 '19 at 18:37

1 Answers1

0

If you look at the error then you will see the message Permission Denied. Your android app doesn't execute in the root level. You need root level privilege to run that command.

You should do something like:

Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());  

Use the DataOutputStream object to write the nmap command out the shell and then read the response using an InputStream

You can find the code code to do this here

Shankha057
  • 1,296
  • 1
  • 20
  • 38