2

I am trying to search the word "hop" from the traceroute output, but somehow its not displaying that line on console. Please let me know where I am going wrong.

Here is my code:

import java.io.*;

public class TestExec {
  public static void main(String[] args) {
    try {
      String[] cmdarray = { "nmap", "--traceroute", "nmap.org" };
      Process p = Runtime.getRuntime().exec(cmdarray);
      BufferedReader in = new BufferedReader(new InputStreamReader(
          p.getInputStream()));
      String line = null;
      while ((line = in.readLine()) != null) {
        if (line.contains("hop")) {
          System.out.println(line);
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
durron597
  • 31,968
  • 17
  • 99
  • 158
sam
  • 61
  • 1
  • 1
  • 4

1 Answers1

1

A few things:

  1. Are you running this in Linux? If you are, you have to run nmap as root. Are you doing so?
  2. I'm not exactly sure what you're trying to look for. In my run of nmap --traceroute nmap.org, there were no lines that contained the word "hop" in lowercase. So even if you are running this program as root, you probably aren't getting very much. I'm fairly certain it doesn't print the word "hop" in lowercase on Windows, either.
durron597
  • 31,968
  • 17
  • 99
  • 158
  • I will add: - I managed to run this from command line (OSx), but I thing it differers from OS to OS. My was running till I haven't terminate it – Lukino Apr 21 '15 at 22:01
  • Thank you so much It was my mistake I gave the search word "Hop".it should be "HOP" . It works now. – sam Apr 21 '15 at 22:02
  • @sam if you feel my answer helped you, please click the checkmark next to the answer. – durron597 Apr 21 '15 at 22:04