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.
This commit is contained in:
Ваше Имя
2025-10-07 18:38:20 +04:00
parent 526b27deaf
commit fcbf6c740c
2 changed files with 13 additions and 9 deletions
+7 -5
View File
@@ -4,7 +4,6 @@
PortScanCli::PortScanCli() PortScanCli::PortScanCli()
: CliBase("Port Scanner Options") : CliBase("Port Scanner Options")
, ip_("")
{ {
} }
@@ -13,14 +12,17 @@ void PortScanCli::setupOptions()
// clang-format off // clang-format off
desc_.add_options() desc_.add_options()
("help,h", "Show help") ("help,h", "Show help")
("ip,H", withDefault(ip_, "<IP>"), "Local IPv4 to scan"); ("ip,H", withDefault(ip_, "<IPv4>"), "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 // clang-format on
} }
std::string PortScanCli::getIp() const int PortScanCli::getPrefix() const
{ {
if (vm_["ip"].empty() == 0) { return vm_.at("prefix").as<int>();
return "127.0.0.1";
} }
std::string PortScanCli::getBaseIp() const
{
return vm_.at("ip").as<std::string>(); return vm_.at("ip").as<std::string>();
} }
+4 -2
View File
@@ -9,11 +9,13 @@ class PortScanCli : public CliBase, protected OptionUtils
public: public:
PortScanCli(); PortScanCli();
std::string getIp() const; int getPrefix() const;
std::string getBaseIp() const;
protected: protected:
void setupOptions() override; void setupOptions() override;
private: private:
std::string ip_; int prefix_{24};
std::string ip_{"10.0.1.0"};
}; };