Port Scanner
Lightweight TCP port scanner for Linux
Loading...
Searching...
No Matches
src
main.cpp
Go to the documentation of this file.
1
#include <iostream>
2
3
#include "../include/printer.hpp"
4
#include "../include/scanner.hpp"
5
6
int
main
(
int
argc,
char
*argv[]) {
7
if
(argc < 3) [[unlikely]] {
8
std::cerr <<
"Usage: "
<< argv[0] <<
" <ip> <port1> [port2]...\n"
;
9
return
1;
10
}
11
12
try
{
13
ipaddr_t
const
ip{argv[1]};
14
std::vector<char const *>
const
ports(&argv[2], &argv[argc]);
15
Scanner
const
scanner{ip, ports};
16
Printer::print
(scanner.scan());
17
}
catch
(std::length_error &e) {
18
std::cerr <<
"Length error: "
<< e.what() <<
'\n'
;
19
return
2;
20
}
catch
(std::bad_alloc &e) {
21
std::cerr <<
"Memory allocation failed: "
<< e.what() <<
'\n'
;
22
return
3;
23
}
catch
(std::invalid_argument &e) {
24
std::cerr <<
"Invalid argument: "
<< e.what() <<
'\n'
;
25
return
4;
26
}
catch
(std::system_error &e) {
27
std::cerr <<
"System error: "
<< e.what() <<
'\n'
;
28
return
5;
29
}
catch
(...) {
30
std::cerr <<
"Unexpected error occurred.\n"
;
31
return
-1;
32
}
33
}
Printer::print
static void print(std::vector< std::pair< port_t, bool > > const &ports)
Prints to stdout the formated information about the ports accessibility.
Definition
printer.cpp:11
Scanner
Definition
scanner.hpp:21
main
int main(int argc, char *argv[])
Definition
main.cpp:6
ipaddr_t
std::string ipaddr_t
IP address type.
Definition
types.hpp:8
Generated on Mon Sep 22 2025 06:30:53 for Port Scanner by
1.9.8