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:
@@ -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_, "<IP>"), "Local IPv4 to scan");
|
||||
("help,h", "Show help")
|
||||
("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
|
||||
}
|
||||
|
||||
std::string PortScanCli::getIp() const
|
||||
int PortScanCli::getPrefix() const
|
||||
{
|
||||
return vm_.at("prefix").as<int>();
|
||||
}
|
||||
|
||||
std::string PortScanCli::getBaseIp() const
|
||||
{
|
||||
if (vm_["ip"].empty() == 0) {
|
||||
return "127.0.0.1";
|
||||
}
|
||||
return vm_.at("ip").as<std::string>();
|
||||
}
|
||||
|
||||
@@ -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"};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user