Reputation: 145
I'm attempting to send input to an nmap process running from a ProcessBuilder but I'm not seeing a response from the running nmap process. I've looked through the nmap source code and it accepts runtime interactive input from a TTY, so I have tried running it with /bin/bash -c
in addition to directly with /usr/bin/nmap
.
I have another thread that reads the stdout from nmap, using this answer. Here is my code:
ProcessBuilder builder = new ProcessBuilder("/usr/bin/nmap", "-v", "-sT", "192.168.1.1-40");
//ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "\"\"/usr/bin/nmap -v -sT 192.168.1.1-40\"\"");
builder.redirectErrorStream(true);
Process proc = builder.start();
LogStreamReader lsr = new LogStreamReader(proc.getInputStream());
Thread thread = new Thread(lsr, "LogStreamReader");
thread.start();
while(thread.isAlive()) {
OutputStream stdin = proc.getOutputStream ();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
System.out.println("Sending input to process...");
writer.write("a");
writer.close();
Thread.sleep(2000);
}
nmap should respond to the writer.write(a)
by printing out the percentage complete/ETA of the scan, but it doesn't.
I've also tried running the writer in a separate thread akin to the LogStreamReader thread, but still nothing...
Am I missing something?
UPDATE:
I've been told nmap has an option --stats-every
which does exactly what I need, so this is solved. I couldn't find a way to write to the tty that nmap uses though.
Upvotes: 1
Views: 914
Reputation: 277
There is a Java library for running Nmap called Nmap4j. You may find that helpful. It is on sourceforge: nmap4j.sourceforge.net.
Upvotes: 1
Reputation: 5995
Nmap's runtime interaction is not taken from STDIN, but from the TTY (reference this nmap-dev thread). I'm not a Java expert, but I don't think ProcessBuilder
supports this kind of interaction.
Upvotes: 1