feat(portscanner): implement port scanning CLI and core logic
Implement command-line interface for port scanning with IP validation and option parsing. Add core scanning logic using Boost.Asio for asynchronous socket checks, including timeout handling and port probing. Update xmake.lua to configure build target and include necessary files.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#include "portscan_cli.hpp"
|
||||
#include <boost/program_options/value_semantic.hpp>
|
||||
#include <cassert>
|
||||
|
||||
PortScanCli::PortScanCli()
|
||||
: CliBase("Port Scanner Options")
|
||||
, ip_("")
|
||||
{
|
||||
}
|
||||
|
||||
void PortScanCli::setupOptions()
|
||||
{
|
||||
// clang-format off
|
||||
desc_.add_options()
|
||||
("help,h", "Show help")
|
||||
("ip,H", withDefault(ip_, "<IP>"), "Local IPv4 to scan");
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
std::string PortScanCli::getIp() const
|
||||
{
|
||||
if (vm_["ip"].empty() == 0) {
|
||||
return "127.0.0.1";
|
||||
}
|
||||
return vm_.at("ip").as<std::string>();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "cli_base.hpp"
|
||||
#include "option_utils.hpp"
|
||||
#include <string>
|
||||
|
||||
class PortScanCli : public CliBase, protected OptionUtils
|
||||
{
|
||||
public:
|
||||
PortScanCli();
|
||||
|
||||
std::string getIp() const;
|
||||
|
||||
protected:
|
||||
void setupOptions() override;
|
||||
|
||||
private:
|
||||
std::string ip_;
|
||||
};
|
||||
Reference in New Issue
Block a user