-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathport_scanner.cpp
More file actions
44 lines (35 loc) · 1.06 KB
/
Copy pathport_scanner.cpp
File metadata and controls
44 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
#include <string>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
bool is_port_open(const std::string& ip, int port) {
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
return false;
}
sockaddr_in server;
server.sin_family = AF_INET;
server.sin_port = htons(port);
inet_pton(AF_INET, ip.c_str(), &server.sin_addr);
int result = connect(sock, (struct sockaddr*)&server, sizeof(server));
close(sock);
return result == 0;
}
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Utilizare: " << argv[0] << " <Adresa_IP>\n";
return 1;
}
std::string ip = argv[1];
std::cout << "Se scanează porturile pentru IP-ul: " << ip << "...\n";
std::vector<int> common_ports = {21, 22, 23, 80, 443, 3306, 8080};
for (int port : common_ports) {
if (is_port_open(ip, port)) {
std::cout << "[+] Port " << port << " - DESCHIS\n";
}
}
std::cout << "Scanare finalizată.\n";
return 0;
}