-
Read arp cache? [Solved]
Heya everyone,
Is there any way to read the ARP cache in java? I can't find any solution for this anywhere. This is what I've tried:
Code:
public static String getARPCache() {
String cmd = "arp -a";
Runtime run = Runtime.getRuntime();
String result = "ARP Cache: ";
try {
Process proc = run.exec(cmd);
proc.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
while ((line = buf.readLine()) != null) {
result += line + "\n";
}
} catch (IOException | InterruptedException ex) {
System.out.println(ex.getMessage());
}
return (result);
}
But it seems that it waits for the process to finish forever. Any ideas what might be causing this, or how to get the ARP cache using another approach?
Thank you very much,
I appreciate your help
Orestis
-
Re: Read arp cache?
Your code is waiting for the process to complete (at line 7) while the process, having filled its buffer, is waiting to write its output.
You don't need a waitFor().
db
-
Re: Read arp cache?
Oh silly me. Thank you very much it works perfectly now.
I appreciate your help