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