Im writing a java program that will scan a range of IP addresses with namp. The code isn't complete and there are a few issues i know i need to work though, so keep that in mind.
What i cant seem to figure out right now is how to view the output of of my nmap scan.
Right now the program will loop though 192.168.0.0 - 192.168.255.255 (infinitely, until i fix it) as confirmed with the system.out.println that's commented out. After that i run namp on the addresses but don't get any output. Ideas?
Below is the chunk of code with the nmap scan, its the first case in my switch statement:
case 1:
IP = "192.168.";
for (int i = 0; i < oct[1].length; i++) {
for (int p = 0; p < oct[2].length; p++) {
String addr = IP + 1 + "." + p;
// System.out.println(addr);
Runtime aRT = Runtime.getRuntime();
Process aProc = aRT.exec("/usr/local/bin/nmap -sn -n" + addr);
//
// HOW TO I VIEW THE RESULTS OF NMAP
//
}
}
break;
And here is the entire program thus far. Everything is in one class right now, i'll break it up later.
public class Start {
public static void main(String args[]) throws IOException {
String s1 = getInput("Please select and IP range to scan: \n" + "\n" +
"1) 192.168.\n" +
"2) 172.28.\n" +
"3) 10.\n"
+ "\n" + ":: ");
int i1 = Integer.parseInt(s1);
String IP = "";
int oct[][] = new int[256][256];
switch (i1) {
case 1:
IP = "192.168.";
for (int i = 0; i < oct[1].length; i++) {
for (int p = 0; p < oct[2].length; p++) {
String addr = IP + 1 + "." + p;
// System.out.println(addr);
Runtime aRT = Runtime.getRuntime();
Process aProc = aRT.exec("/usr/local/bin/nmap -sn -n" + addr);
//
// HOW TO I VIEW THE RESULTS OF NMAP
//
}
}
break;
case 2:
System.out.println("case2");
break;
case 3:
System.out.println("case3");
break;
case 99:
System.out.println("case99");
break;
default:
System.out.println("default");
break;
}
}
private static String getInput(String prompt) {
BufferedReader stdin = new BufferedReader(
new InputStreamReader(System.in));
System.out.print(prompt);
System.out.flush();
try {
return stdin.readLine();
} catch (Exception e) {
return "Error: " + e.getMessage();
}
}
}