I am trying to do an application which works quite similar to Fing. I would like to get the IP addresses and the Mac address from all devices connected to the same network.
I tried to use a nmap command (used in Linux) but unfortunately it doesn't work. Anybody knows how could I get this information?
EDIT:
The Nmap address which I use is the following.
try {
StringBuffer output = new StringBuffer();
Process proc = Runtime.getRuntime().exec("sudo nmap -sP 192.168.1.0/24");
proc.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
Log.e("RESULT",output.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
And then it throws an Exception:
07-30 17:51:55.789: W/System.err(25319): java.io.IOException: Error running exec(). Command: [sudo, nmap, -sP, 192.168.1.0/24] Working Directory: null Environment: null
07-30 17:51:55.789: W/System.err(25319): at java.lang.ProcessManager.exec(ProcessManager.java:224)