-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelware.c
More file actions
51 lines (42 loc) · 1.14 KB
/
Copy pathtelware.c
File metadata and controls
51 lines (42 loc) · 1.14 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
45
46
47
48
49
50
51
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <string.h>
#pragma comment(lib, "ws2_32.lib")
#define SERVER "Put IP here"
#define PORT 23
#define INTERVAL 120 // secondes
int main() {
WSADATA wsa;
SOCKET s;
struct sockaddr_in server;
char* message = "R\n";
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) {
printf("Error WSAStartup\n");
return 1;
}
while (1) {
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == INVALID_SOCKET) {
printf("Error socket\n");
break;
}
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr.s_addr = inet_addr(SERVER);
if (connect(s, (struct sockaddr*)&server, sizeof(server)) < 0) {
printf("Cannot connect\n");
}
else {
printf("Connected.\n");
send(s, message, (int)strlen(message), 0);
printf("Command send.\n");
closesocket(s);
printf("Disconnected.\n");
}
Sleep(INTERVAL * 1000);
}
WSACleanup();
return 0;
}