Esempio n. 1
0
        static private void WakeFunction(string ip, string mac, int port)
        {
            string MAC_ADDRESS = string.Join("", mac.Split('-'));

            WOLClass client = new WOLClass();

            client.EnableBroadcast = true;

            client.Connect(IPAddress.Parse(ip), port);

            client.SetClientToBrodcastMode();
            //set sending bites
            int counter = 0;

            //buffer to be send, this is structure of magic packet
            byte[] bytes = new byte[1024];   // more than enough :-)
                                             //first 6 bytes should be 0xFF
            for (int y = 0; y < 6; y++)
            {
                bytes[counter++] = 0xFF;
            }
            //now repeate MAC 16 times
            for (int y = 0; y < 16; y++)
            {
                int i = 0;
                for (int z = 0; z < 6; z++)
                {
                    bytes[counter++] =
                        byte.Parse(MAC_ADDRESS.Substring(i, 2),
                                   NumberStyles.HexNumber);
                    i += 2;
                }
            }

            //now send wake up packet
            int reterned_value = client.Send(bytes, 1024);

            if (reterned_value > 0)
            {
                Console.Write("Wake-on-LAN packet sent to IP: {0}, MAC:{1}", ip, mac);
            }
            else
            {
                Console.Write("Wake-on-LAN send packet failed: {0}, MAC:{1}", ip, mac);
            }
        }
Esempio n. 2
0
        private void WakeFunction(string MAC_ADDRESS)
        {
            WOLClass client = new WOLClass();

            client.Connect(new
                           IPAddress(0xffffffff), //255.255.255.255  i.e broadcast
                           0x2fff);               // port=12287 default WOL port

            client.SetClientToBrodcastMode();

            //set sending bites
            int counter = 0;

            //buffer to be send
            byte[] bytes = new byte[1024];   // more than enough :-)

            //first 6 bytes should be 0xFF
            for (int y = 0; y < 6; y++)
            {
                bytes[counter++] = 0xFF;
            }

            //now repeate sneding MAC 16 times
            for (int y = 0; y < 16; y++)
            {
                int i = 0;
                for (int z = 0; z < 6; z++)
                {
                    bytes[counter++] =
                        byte.Parse(MAC_ADDRESS.Substring(i, 2),
                                   NumberStyles.HexNumber);
                    i += 2;
                }
            }

            //now send wake up packet
            int reterned_value = client.Send(bytes, 1024);
        }
Esempio n. 3
0
        private void WakeFunction(string MAC_ADDRESS)
        {
            WOLClass client = new WOLClass();
            client.Connect(new
               IPAddress(0xffffffff),  //255.255.255.255  i.e broadcast
               0x2fff); // port=12287 default WOL port

            client.SetClientToBrodcastMode();

            //set sending bites
            int counter = 0;

            //buffer to be send
            byte[] bytes = new byte[1024];   // more than enough :-)

            //first 6 bytes should be 0xFF
            for (int y = 0; y < 6; y++)
                bytes[counter++] = 0xFF;

            //now repeate sneding MAC 16 times
            for (int y = 0; y < 16; y++)
            {
                int i = 0;
                for (int z = 0; z < 6; z++)
                {
                    bytes[counter++] =
                        byte.Parse(MAC_ADDRESS.Substring(i, 2),
                        NumberStyles.HexNumber);
                    i += 2;
                }
            }

            //now send wake up packet
            int reterned_value = client.Send(bytes, 1024);
        }