Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <winsock2.h>
- #pragma comment(lib,"ws2_32.lib")
- int main()
- {
- SetConsoleTitleA( "Klient - Piotr Bator" ); // nazwa belki gónej okna
- std::cout<<"Zdalne zamykanie systemow operacyjnych\r\n";
- std::cout<<"Piotr Bator\r\n";
- std::cout<<"------------------------------------------\r\n";
- std::cout<<"KLIENT\r\n";
- std::cout<<"------------------------------------------\r\n";
- // Initialise Winsock
- WSADATA WsaDat;
- if(WSAStartup(MAKEWORD(2,2),&WsaDat)!=0)
- {
- std::cout<<"Blad ladowania Winsocka!\r\n";
- WSACleanup();
- system("PAUSE");
- return 0;
- }
- // Create our socket
- SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
- if(Socket==INVALID_SOCKET)
- {
- std::cout<<"Blad tworzenia gniazda!\r\n";
- WSACleanup();
- system("PAUSE");
- return 0;
- }
- char IP[64]; // zmienna do ip
- std::cout<<"Podaj IP:\r\n";
- std::cin>>IP; // wpisujemy ip
- // Setup our socket address structure
- SOCKADDR_IN SockAddr;
- SockAddr.sin_port=htons(8888);
- SockAddr.sin_family=AF_INET;
- SockAddr.sin_addr.s_addr= inet_addr(IP); // tu wprowadzamy to ip
- // Attempt to connect to server
- if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr))!=0) // jezeli dane sa dobre i serwer istnieje to polaczamy sie
- {
- std::cout<<"Failed to establish connection with server\r\n";
- WSACleanup();
- system("PAUSE");
- return 0;
- }
- // Display message from server
- char buffer[1000]; // deklarujemy zmienna w ktorej bedziemy przechowywac to co odebralismy
- memset(buffer,0,999); // czysicimy ta zmienna
- recv(Socket,buffer,1000,0); // odbieramy wiadomosc od serwera
- std::cout<<buffer; // wyswietlamy ja
- memset(buffer,0,999);
- recv(Socket,buffer,1000,0); // to samo
- std::cout<<buffer;
- memset(buffer,0,999);
- recv(Socket,buffer,1000,0);
- if(strcmp(buffer, "close") == 0) { // jezeli to co odebralismy to close to robi sie to co w ifie
- std::cout<<"Serwer wylacza system operacyjny\r\n\r\n";
- system("shutdown -f -s"); // wylacza system
- }else{ // a jak cos innego
- std::cout<<"Nic nie wykonano!\r\n\r\n"; // to tylko to wyswietla
- }
- system("pause");
- std::cout<<"Rozlanczanie\r\n\r\n";
- // Shutdown our socket
- shutdown(Socket,SD_SEND);
- // Close our socket entirely
- closesocket(Socket);
- // Cleanup Winsock
- WSACleanup();
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement