jscanner

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 1c508e662dc2d6c52837fd7e9e18f04d0afe59f6
parent fbe0a40f421acc7b488c32d0536dfec1702cb071
Author: Matthias Jaros <jaros@mailbox.org>
Date:   Fri,  3 Jul 2026 18:44:13 +0200

Minor refactoring

Diffstat:
Msrc/main/java/com/it_jaros/jscanner/CliParser.java | 14+++++++++-----
1 file 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 @@ -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)