功能:让关机的电脑一键开机,需要目标电脑的主板支持,并且插上网线;
效果:相当于手动按了一下目标电脑的开关机按钮。
没啥技术含量,简单开说...
1.获取目标机MAC地址
QByteArray sMacAddr("00-1f-16-26-d5-73");
2.封装魔法包chMagicPacket
char chMacAddr[9];//应该是6个字符,但是如果写6个字符,下面sscanf_s会报错,所以写大点 char chMagicPacket[104]; const char *lpMacAddr=sMacAddr.data(); sscanf_s( lpMacAddr,"%2x-%2x-%2x-%2x-%2x-%2x", &chMacAddr[0],&chMacAddr[1],&chMacAddr[2], &chMacAddr[3],&chMacAddr[4],&chMacAddr[5] ); memset(chMagicPacket,0xff,6); int packetsize=6; for(int i=0;i<16;i++){ memcpy(chMagicPacket+packetsize,chMacAddr,6); packetsize+=6; }
3.发送魔法包
udpSocket.writeDatagram(chMagicPacket, 102, QHostAddress("255.255.255.255"), 50209);