From fcbf6c740cc56d2ec1b2aba16dc77c4f782d30c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=88=D0=B5=20=D0=98=D0=BC=D1=8F?= Date: Tue, 7 Oct 2025 18:38:20 +0400 Subject: [PATCH] feat(portscan): add CIDR prefix support and base IP handling Add CIDR prefix option to define IP range for scanning, with default base IP of 10.0.1.0 and prefix 24. Update methods to retrieve base IP and prefix separately. --- src/cli/portscan_cli.cpp | 16 +++++++++------- src/cli/portscan_cli.hpp | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/cli/portscan_cli.cpp b/src/cli/portscan_cli.cpp index 0e637b2..2eefe57 100644 --- a/src/cli/portscan_cli.cpp +++ b/src/cli/portscan_cli.cpp @@ -4,7 +4,6 @@ PortScanCli::PortScanCli() : CliBase("Port Scanner Options") - , ip_("") { } @@ -12,15 +11,18 @@ void PortScanCli::setupOptions() { // clang-format off desc_.add_options() - ("help,h", "Show help") - ("ip,H", withDefault(ip_, ""), "Local IPv4 to scan"); + ("help,h", "Show help") + ("ip,H", withDefault(ip_, ""), "Base IPv4 inside your LAN (e.g. 10.0.1.42)") + ("prefix,p", withDefault(prefix_, "<0..32>"), "CIDR prefix length (e.g. 24)"); // clang-format on } -std::string PortScanCli::getIp() const +int PortScanCli::getPrefix() const +{ + return vm_.at("prefix").as(); +} + +std::string PortScanCli::getBaseIp() const { - if (vm_["ip"].empty() == 0) { - return "127.0.0.1"; - } return vm_.at("ip").as(); } diff --git a/src/cli/portscan_cli.hpp b/src/cli/portscan_cli.hpp index bf12444..5b5412f 100644 --- a/src/cli/portscan_cli.hpp +++ b/src/cli/portscan_cli.hpp @@ -9,11 +9,13 @@ class PortScanCli : public CliBase, protected OptionUtils public: PortScanCli(); - std::string getIp() const; + int getPrefix() const; + std::string getBaseIp() const; protected: void setupOptions() override; private: - std::string ip_; + int prefix_{24}; + std::string ip_{"10.0.1.0"}; };