예제 #1
0
        public static void runWakeOnLan(List <string> macAddress, List <string> ipAddresses)
        {
            for (int i = 0; i < macAddress.Count; i++)
            {
                string MacAddress = macAddress[i];
                if (MacAddress != "")
                {
                    try
                    {
                        MacAddress = MacAddress.Replace(":", "-");
                        MacAddress = MacAddress.Replace(".", "-");
                        MacAddress = MacAddress.Replace("_", "-");
                        MacAddress = MacAddress.Replace(" ", "-");
                        MacAddress = MacAddress.Replace(",", "-");
                        MacAddress = MacAddress.Replace(";", "-");

                        MacAddress = MacAddress.Replace("-", "");
                        byte[] mac = new byte[6];
                        for (int k = 0; k < 6; k++)
                        {
                            mac[k] = Byte.Parse(MacAddress.Substring(k * 2, 2), System.Globalization.NumberStyles.HexNumber);
                        }
                        foreach (string IP in ipAddresses)
                        {
                            var endPoint = new IPEndPoint(getBroadcastIP(IP), 0);
                            endPoint.SendWol(mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }