blob: 442e7c132469870ad894f9f73530a77d8a283a3b (
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
37
38
39
40
41
42
43
44
45
46
|
package com.it_jaros.networkScanner;
public class CliParser {
public ScanTarget parseArgs(String[] args) {
if (args.length < 1 || args[0].trim().equals("")) {
throw new IllegalArgumentException("No argument given");
}
String currentArg;
String target = null;
int socketLimit = 1000;
int delayInMillis = 0;
for (int i = 0; i < args.length; i++) {
currentArg = args[i];
if (!currentArg.startsWith("-")) {
target = currentArg;
continue;
}
try {
switch (currentArg) {
case "--help", "-h":
App.usageAndExit();
case "--socketLimit", "-sl":
socketLimit = Integer.parseInt(args[++i]);
break;
case "--delay", "-d":
delayInMillis = Integer.parseInt(args[++i]);
break;
default:
throw new IllegalArgumentException("No such param " + currentArg);
}
} catch (IndexOutOfBoundsException | NumberFormatException e) {
System.out.printf("Missing or wrong argument for option %s", currentArg);
System.exit(2);
}
}
System.out.printf(
"Scanning target '%s' with socketLimit(%s), delayInMillis(%s) \n", target, socketLimit, delayInMillis);
return new ScanTarget(target, socketLimit, delayInMillis);
}
}
|