Computer im Netzwerk hochfahren

  • VB.NET

Es gibt 14 Antworten in diesem Thema. Der letzte Beitrag () ist von BreadShirt.

    Oder du nutz WakeOnLan.
    Dann brauchst du keine Fritzbox :)
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Also ich hab 3 Buttons:
    -Verbindung trennen
    -Computer im Netzwerk herunterfahren
    -Computer im Netzwerk hochfahren

    Die ersten beiden habe ich gemeistert. Nur jetzt bekomm ich beim dritten nichts hin... Hätte jemand ne Idee, so das der User der davor sitzt nur den Button klicken muss und sein Laptop (der z.B. am LAN hängt) hochgefahren wird?
    Dann mach das über wakeonlan. Ich habe hier noch einen alten c++ code von mir. Im grunde musst du nur ein magic packet aus der mac addresse bilden, und über udp an den pc senden. Vorrausgesetzt dieser hat wol aktiviert / verfügbar, ist im Netzwerk, und hat Strom.

    Code. (Nicht wirklich gut. Lediglich um Vorgehensweise zu demonstrieren.)

    Spoiler anzeigen

    C-Quellcode

    1. #include <iostream>
    2. #include <sys/socket.h>
    3. #include <string.h>
    4. #include <sstream>
    5. #include <array>
    6. #include <sys/types.h>
    7. #include <netinet/in.h>
    8. #include <netdb.h>
    9. #include <arpa/inet.h>
    10. #include <fstream>
    11. #include <sys/stat.h>
    12. #include <cstdlib>
    13. #include <cstring>
    14. #include <thread>
    15. #include <chrono>
    16. using namespace std;
    17. unsigned char mac[6];
    18. unsigned char pack[102];
    19. const char * ip;
    20. int timer = 270;
    21. int main();
    22. void getConfig()
    23. {
    24. ifstream read("./config.txt");
    25. if(read.is_open())
    26. {
    27. string l1, l2, l3;
    28. getline(read,l1);
    29. getline(read,l2);
    30. getline(read,l3);
    31. int mp = 0;
    32. for(int i = 0; i < l1.size(); i++)
    33. {
    34. if(l1[i] == ':')
    35. {
    36. mac[mp] = strtoul(l1.substr(i-2,2).c_str(),NULL,16);
    37. mp++;
    38. }
    39. }
    40. mac[mp] = strtoul(l1.substr(l1.size()-2,2).c_str(),NULL,16);
    41. ip = l2.c_str();
    42. istringstream is(l3);
    43. is >> timer;
    44. read.close();
    45. }
    46. else
    47. {
    48. read.close();
    49. cout << "Please create config file first!" << endl;
    50. main();
    51. }
    52. }
    53. void createConfig()
    54. {
    55. mkdir("./", 777);
    56. ofstream file("./config.txt");
    57. file << endl << endl << endl;
    58. file.close();
    59. }
    60. void editConfig()
    61. {
    62. ifstream conf("./config.txt");
    63. if(conf.is_open())
    64. {
    65. string mac;
    66. string ip;
    67. string times;
    68. cout << "Mac: ";
    69. cin >> mac;
    70. cout << endl << "IP: ";
    71. cin >> ip;
    72. cout << endl << "Timer (s): ";
    73. cin >> times;
    74. cout << endl << "Saving..." << endl;
    75. conf.close();
    76. ofstream writer("./config.txt");
    77. writer << mac << endl << ip << endl << times;
    78. cout << "Saved!" << endl << endl;
    79. }
    80. else
    81. {
    82. conf.close();
    83. cout << "Config dont exist!" << endl << "create new file..." << endl;
    84. createConfig();
    85. cout << "Done." << endl;
    86. editConfig();
    87. }
    88. }
    89. void createPacket()
    90. {
    91. for(int i = 0; i < 6; i++)//Die ersten 6 sind 0xFF
    92. {
    93. pack[i] = 0xff;
    94. }
    95. for(int i = 1; i <= 16; i++)
    96. {
    97. memcpy(&pack[i * 6], &mac, 6 * sizeof(unsigned char)); //danach kommt die MAC Addresse 16 mal
    98. }
    99. }
    100. void send()
    101. {
    102. int udpSocket;
    103. struct sockaddr_in udpClient, udpServer;
    104. int broadcast = 1;
    105. udpSocket = socket(AF_INET, SOCK_DGRAM, 0);
    106. if (setsockopt(udpSocket, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof broadcast) == -1) {
    107. perror("setsockopt (SO_BROADCAST)");
    108. //exit(1);
    109. }
    110. udpClient.sin_family = AF_INET;
    111. udpClient.sin_addr.s_addr = INADDR_ANY;
    112. udpClient.sin_port = 0;
    113. bind(udpSocket, (struct sockaddr*)&udpClient, sizeof(udpClient));
    114. udpServer.sin_family = AF_INET;
    115. udpServer.sin_addr.s_addr = inet_addr(ip);
    116. udpServer.sin_port = htons(9);
    117. sendto(udpSocket, &pack, sizeof(unsigned char) * 102, 0, (struct sockaddr*)&udpServer, sizeof(udpServer));
    118. }
    119. void loop()
    120. {
    121. while(true)
    122. {
    123. std::this_thread::sleep_for(std::chrono::seconds(timer));
    124. send();
    125. cout << "[INFO] Magic packet sent" << endl;
    126. }
    127. }
    128. int main(void)
    129. {
    130. string com;
    131. cout << "WOL CustomWake" << endl << "Copyright 2014 by ," << endl << "";
    132. cout << endl << "What you want to do?" << endl;
    133. menu:
    134. cin >> com;
    135. if(com == "help" || com == "?")
    136. {
    137. cout << "Help:" << endl;
    138. cout << "?/help : help " << endl;
    139. cout << "start/s : start" << endl;
    140. cout << "config/cfg : Edit config" << endl;
    141. goto menu;
    142. }
    143. else if(com == "start" || com == "s")
    144. {
    145. cout << endl << endl << "Load config & Create Mac array.." << endl;
    146. getConfig();
    147. cout << "Done!" << endl << "Create magic packet.." << endl;
    148. createPacket();
    149. cout << "Done!" << endl;
    150. cout << "Sending Data.." << endl;
    151. send();
    152. cout << "Done! Please check your WOL target system!" << endl;
    153. loop();
    154. }
    155. else if(com == "config" || com == "cfg")
    156. {
    157. editConfig();
    158. main();
    159. }
    160. else
    161. {
    162. main();
    163. }
    164. return 0;
    165. }


    Mehr dazu: de.wikipedia.org/wiki/Wake_On_LAN

    lg Marcel

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcel1997“ ()