0

is there any way to start the command 'arp'.

My tries:

Runtime rt = Runtime.getRuntime();
proc = rt
  1. .exec("arp") -> got an IOException
  2. .exec("/proc/net/arp") -> got an IOException as well (found out over the adb shell, that a /proc/net/arp exists)

Also tried a shell solution:

String sPrefix="/system/bin/sh -c 'proc/net/arp;";
String sPostfix="'";
Runtime rt = Runtime.getRuntime();

proc = rt.exec(sPrefix+sPostfix); // sh -c 'cd someplace; echo do something'
InputStreamReader reader = new InputStreamReader(proc.getInputStream());
BufferedReader buffer = new BufferedReader(reader);
String line = "";
while ((line = buffer.readLine()) != null) {
   echo.append(line + "\n");
}           

but got no return value.

Have anyone an idea :-/?

P.T.
  • 24,557
  • 7
  • 64
  • 95
Tim Ewald
  • 21
  • 1
  • 3

1 Answers1

2

/proc/net/arp is not a command, it's an ARP table. It's a text file you can read:

  StringBuffer echo = new StringBuffer();
  try {
    BufferedReader br = new BufferedReader(new FileReader("/proc/net/arp"));
    String line = "";
    while((line = br.readLine()) != null) echo.append(line + "\n");
    br.close();
  }
  catch(Exception e) { Log.e(TAG, e.toString()); }

The table itself has the format:

IP address        HW type    Flags     HW address           Mask   Device
192.168.178.21    0x1        0x2       00:1a:2b:3c:4d:5e    *      tiwlan0
192.168.178.34    0x1        0x2       1a:2b:3c:4d:5e:6f    *      tiwlan1
...
Igor F.
  • 2,649
  • 2
  • 31
  • 39
  • Unfortunately it seems newer versions of android (I think 4.0+) Don't keep this information anymore. The tables are blank. – Chris.Jenkins Jul 10 '15 at 16:45