C#远程开机代码

 

        /// <summary>
        /// 远程开机,网卡需要具备远程唤醒功能
        /// </summary>
        /// <param name="mac">网卡物理地址字符数组</param>
        public static void WakeUp(byte[] mac)
        {
            UdpClient client = new UdpClient();
            client.Connect(IPAddress.Broadcast, 9090);

            byte[] packet = new byte[17 * 6];

            for (int i = 0; i < 6; i++)
                packet[i] = 0xFF;

            for (int i = 1; i <= 16; i++)
                for (int j = 0; j < 6; j++)
                    packet[i * 6 + j] = mac[j];

            int result = client.Send(packet, packet.Length);
        }

        // 唤醒按钮事件代码

        private void button_Click(object sender, EventArgs e)
        {
            byte[] mac = new byte[6];
            mac[0] = 0x00;
            mac[1] = 0x01;
            mac[2] = 0x80;
            mac[3] = 0x79;
            mac[4] = 0x08;
            mac[5] = 0xD8;

            WakeUp(mac);
        }

你可能感兴趣的:(object,C#,byte,button)