blob: 8e15730f7b78487c6964101ead994defb3a81c1e (
plain) (
blame)
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
|
package com.it_jaros.networkScanner;
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());
printResults(scanner.scan(options));
} 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) {
results.forEach(App::printResult);
}
private static void printResult(ScanResult result) {
String ports = result.openPorts().stream().mapToObj(String::valueOf).collect(Collectors.joining(","));
String output = "[" + result.target() + "]:";
if (ports.equals("")) {
output = output + "No open ports found";
} else {
output = output + ports;
}
System.out.print(output + "\n");
}
}
|