Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Read arp cache?

  1. #1
    orestis125 is offline Member
    Join Date
    Jun 2012
    Posts
    13
    Rep Power
    0

    Default 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:

    Java 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
    Last edited by orestis125; 09-28-2012 at 04:27 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default 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
    orestis125 likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    orestis125 is offline Member
    Join Date
    Jun 2012
    Posts
    13
    Rep Power
    0

    Default Re: Read arp cache?

    Oh silly me. Thank you very much it works perfectly now.

    I appreciate your help

Similar Threads

  1. Binary Cache
    By Collider in forum New To Java
    Replies: 10
    Last Post: 05-03-2012, 05:22 PM
  2. Configration or Cache (JCS)
    By yatin110 in forum New To Java
    Replies: 0
    Last Post: 06-24-2010, 12:06 PM
  3. Cache Objects
    By jonnytabpni in forum New To Java
    Replies: 2
    Last Post: 12-24-2009, 10:30 AM
  4. creating cache
    By Omarero in forum New To Java
    Replies: 1
    Last Post: 02-01-2009, 08:31 PM
  5. cache problem in jsp
    By lpwing in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 01-15-2008, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •