1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package com.it_jaros.network_scanner;
import java.util.BitSet;
import java.util.List;
import java.util.stream.Collectors;
public class App {
public static void main(String[] args) {
CliParser cliParser = new CliParser();
try {
ScanOptions options = cliParser.parseArgs(args);
Scanner scanner = new Scanner(options.openSocketLimit(), options.timeoutInMillis(),
options.delayInMillis(), options.maxWorkersPerHost(), options.maxTargetsLimit());
printResults(scanner.scan(options), options.showFilteredPorts());
} catch (IllegalArgumentException e) {
System.out.printf("Error while parsing arguments: %s", e.getMessage());
cliParser.usageAndExit();
} catch (Exception e) {
System.out.printf("ERROR: %s", e.getMessage());
}
}
public static void printResults(List<ScanResult> results, boolean showFilteredPorts) {
results.forEach((ScanResult r) -> printResult(r, showFilteredPorts));
}
private static void printResult(ScanResult result, boolean showFilteredPorts) {
if (result.openPorts().isEmpty() && (!showFilteredPorts || result.filteredPorts().isEmpty())) {
return;
}
System.out.println(result.target());
if (!result.openPorts().isEmpty()) {
System.out.printf("\t (%d) open:\t%s%n", result.openPorts().cardinality(), map(result.openPorts()));
}
if (showFilteredPorts && !result.filteredPorts().isEmpty()) {
System.out.printf("\t (%d) filtered:\t%s%n", result.filteredPorts().cardinality(), map(result.filteredPorts()));
}
System.out.println();
}
private static String map(BitSet ports) {
return ports.stream().mapToObj(String::valueOf).collect(Collectors.joining(","));
}
}
|