diff --git a/README.md b/README.md index 8c39ff1..914f3f2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ Allowed options: --help display help message --host arg (=127.0.0.1) set host --port arg (=0-1024) set port range in the format 'begin[-end]' - --protocol arg (=tcp) set protocol (tcp/udp) --show arg (=open) display only 'open', 'closed', or 'all' ports ``` diff --git a/src/Main.cpp b/src/Main.cpp index 1d28c36..022399e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -15,7 +15,6 @@ int main(int argc, char *argv[]) { ("help", "display help message") ("host", po::value()->default_value("127.0.0.1"), "set host") ("port", po::value()->default_value("0-1024"), "set port range in the format 'begin[-end]'") - ("protocol", po::value()->default_value("tcp"), "set protocol (tcp/udp)") ("show", po::value()->default_value("open"), "display only 'open', 'closed', or 'all' ports") ; // clang-format on @@ -59,40 +58,32 @@ int main(int argc, char *argv[]) { return 1; } - const std::string protocol = vm["protocol"].as(); - if (!(protocol == "tcp" || protocol == "udp")) { - std::cerr << "Error: Invalid value for --protocol. Use 'tcp' or 'udp'." << std::endl; - return 1; - } - const std::string show = vm["show"].as(); if (show != "open" && show != "closed" && show != "all") { std::cerr << "Error: Invalid value for --show. Use 'open', 'closed', or 'all'." << std::endl; return 1; } - if (protocol == "tcp") { - boost::asio::io_context io_service; - std::map> sockets; - for (unsigned int port = portBegin; port <= portEnd; port++) { - boost::asio::ip::tcp::resolver resolver(io_service); - boost::asio::ip::tcp::resolver::query query(host, std::to_string(port)); - try { - boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query); - auto socket = std::make_unique(io_service); - socket->async_connect(iterator->endpoint(), [port, protocol, show](const boost::system::error_code &error) -> void { - if ((error && show == "closed") || (!error && show == "open")) { - std::cout << "Port " << port << "/" << protocol << " is " << (error ? "closed" : "open") << "." << std::endl; - } - }); - sockets.emplace(port, std::move(socket)); - } catch (const boost::system::system_error &e) { - std::cerr << e.what() << std::endl; - return 1; - } + boost::asio::io_context io_service; + std::map> sockets; + for (unsigned int port = portBegin; port <= portEnd; port++) { + boost::asio::ip::tcp::resolver resolver(io_service); + boost::asio::ip::tcp::resolver::query query(host, std::to_string(port)); + try { + boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query); + auto socket = std::make_unique(io_service); + socket->async_connect(iterator->endpoint(), [port, show](const boost::system::error_code &error) -> void { + if ((error && show == "closed") || (!error && show == "open")) { + std::cout << "Port " << port << "/tcp is " << (error ? "closed" : "open") << "." << std::endl; + } + }); + sockets.emplace(port, std::move(socket)); + } catch (const boost::system::system_error &e) { + std::cerr << e.what() << std::endl; + return 1; } - io_service.run(); } + io_service.run(); return 0; }