コード例 #1
0
        //now use this class
        //MAC_ADDRESS should  look like '013FA049'
        public void WakeFunction(string MAC_ADDRESS)
        {
            WOLClass client = new WOLClass();

            client.Connect(new IPAddress(0xffffffff), //255.255.255.255  i.e broadcast
                           0x2fff);                   // port=12287 let's use this one
            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 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);
        }
コード例 #2
0
ファイル: WakeUp.cs プロジェクト: radtek/Netvision
        //now use this class
        //MAC_ADDRESS should  look like '013FA049'
        public void WakeFunction(string macAddress, string ipAddress, string subnetMask = null)
        {
            subnetMask = "255.255.224.0";

            WOLClass client = new WOLClass();

            client.SetClientToBrodcastMode();

            Byte[] datagram = new byte[102];

            for (int i = 0; i <= 5; i++)
            {
                datagram[i] = 0xff;
            }

            string[] macDigits = null;
            if (macAddress.Contains("-"))
            {
                macDigits = macAddress.Split('-');
            }
            else
            {
                macDigits = macAddress.Split(':');
            }

            if (macDigits.Length != 6)
            {
                throw new ArgumentException("Incorrect MAC address supplied!");
            }

            int start = 6;

            for (int i = 0; i < 16; i++)
            {
                for (int x = 0; x < 6; x++)
                {
                    datagram[start + i * 6 + x] = (byte)Convert.ToInt32(macDigits[x], 16);
                }
            }

            IPAddress address          = IPAddress.Parse(ipAddress);
            IPAddress mask             = IPAddress.Parse(subnetMask);
            IPAddress broadcastAddress = address.GetBroadcastAddress(mask);

            client.Send(datagram, datagram.Length);
        }