diff options
| author | 2026-07-03 18:44:13 +0200 | |
|---|---|---|
| committer | 2026-07-09 09:59:28 +0200 | |
| commit | f740a93f0f9f62b51dc385241354dadb07120258 (patch) | |
| tree | 00a1e83ce314ababa55e8d1354757d3f7f97c1f7 | |
| parent | 09035b78a2aa6f8f0702d40288ef44a76ef7a6ac (diff) | |
Minor refactoring
| -rw-r--r-- | src/main/java/com/it_jaros/jscanner/CliParser.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/main/java/com/it_jaros/jscanner/CliParser.java b/src/main/java/com/it_jaros/jscanner/CliParser.java index 0d6fb7b..707abb5 100644 --- a/src/main/java/com/it_jaros/jscanner/CliParser.java +++ b/src/main/java/com/it_jaros/jscanner/CliParser.java @@ -44,7 +44,7 @@ public class CliParser { usageAndExit(0); break; case "--input", "-i": - hostsFile = requireValue(args, ++i, currentArg); + hostsFile = getArgument(args, ++i, currentArg); break; case "--maxHostsLimit", "-m": maxHostsLimit = parseIntOption(args, ++i, currentArg); @@ -53,7 +53,7 @@ public class CliParser { maxWorkersPerHost = parseIntOption(args, ++i, currentArg); break; case "--ports", "-p": - ports = requireValue(args, ++i, currentArg); + ports = getArgument(args, ++i, currentArg); break; case "--quiet", "-q": quiet = true; @@ -72,10 +72,14 @@ public class CliParser { } } + if (hostsArgv.isEmpty() && hostsFile == null) { + throw new IllegalStateException("No input provided. Check with --help for available options."); + } + return new ScanOptions(hostsArgv.stream().toList(), socketLimit, delayInMillis, timeoutInMillis, maxWorkersPerHost, maxHostsLimit, ports, showFilteredPorts, disableOnlineCheck, hostsFile, quiet, bannerRecognition); } - private String requireValue(String[] args, int index, String option) { + private String getArgument(String[] args, int index, String option) { if (index >= args.length) { throw new IllegalArgumentException(String.format("Missing argument for option %s", option)); } @@ -83,7 +87,7 @@ public class CliParser { } private int parseIntOption(String[] args, int index, String option) { - String value = requireValue(args, index, option); + String value = getArgument(args, index, option); try { return Integer.parseInt(value); } catch (NumberFormatException e) { @@ -103,7 +107,7 @@ public class CliParser { --bannerRecognition, -b:\tEnable banner recognition to find out which service is running behind port (Default :%b) --delay, -d:\t\tWaiting period in millis for connection attempts for a host (Default: %d) --disableOnlineCheck, -do:\tDon't check if Host is reachable (Default: %b) - --input, -i:\t\tRead file to get host targets to scan (Default: null) + --input, -i:\t\tRead file to get host targets to scan. If set to "-" than Stdin is read (Default: null) --maxHostsLimit, -m:\tMax number of hosts that are scanned at the same time (Default: %d) --maxWorkersPerHost, -mh:\tVirtual Worker Threads run per Host. Higher doesn't mean necessarily faster. But the more you use the more RAM is required (Default: %d) --ports, -p:\t\tDefine ports to be scanned (Default: %s) |
