
Due to the fact, that a WOL packet is always a broadcast packet (dest-ip 255.255.255.255) it won't leave your local network and will always be dropped from router, gateways or any other bridge between to networks (e.g. to allow such a packet and let it flow from sender to receiver. It is a pure network problem, where you have to configure your router, gateways, ids-systems, etc. The third problem can't also be solved by C#. This can't be programmed, due to the fact that every network adapter has another implementation of that function and how it can be enabled.

Just open the device manager and take a look into the properties of your network adapter, if such an option exists and if you can enable it. The second one is something you can only achieve by configuring your network adapter. Using UdpClient client = new(new IPEndPoint(localIpAddress, 0)) Īwait client.SendAsync(magicPacket, magicPacket.Length, new IPEndPoint(multicastIpAddress, 9)) įor the WOL problem you have to clarify three problems to get it to work:Īs you already found on the net there are existing several solutions for the first problem programmed in C# (and after skimming your links, I would start with the first one). Static async Task SendWakeOnLan(IPAddress localIpAddress, IPAddress multicastIpAddress, byte magicPacket) IEnumerable data = Enumerable.Repeat(macBytes, 16).SelectMany(m => m) // then 16 times MacAddress IEnumerable header = Enumerable.Repeat((byte)0xff, 6) //First 6 times 0xff

UnicastIPAddressInformation? unicastIPAddressInformation = ((u) =>īyte macBytes = Convert.FromHexString(macAddress)

MacAddress = Regex.Replace(macAddress, "", "") Static byte BuildMagicPacket(string macAddress) // MacAddress in any standard HEX format U.Address.AddressFamily = AddressFamily.InterNetwork & !iPInterfaceProperties.GetIPv4Properties().IsAutomaticPrivateAddressingActive).FirstOrDefault() U.Address.AddressFamily = AddressFamily.InterNetworkV6 & !u.Address.IsIPv6LinkLocal).FirstOrDefault() Īwait SendWakeOnLan(unicastIPAddressInformation.Address, multicastIpAddress, magicPacket) Įlse if (multicastIpAddress.ToString().Equals("224.0.0.1")) // Ipv4: All hosts on LAN UnicastIPAddressInformation unicastIPAddressInformation = ((u) => If (multicastIpAddress.ToString().StartsWith("ff02::1%", StringComparison.OrdinalIgnoreCase)) // Ipv6: All hosts on LAN (with zone index) IPAddress multicastIpAddress = multicastIPAddressInformation.Address IPInterfaceProperties iPInterfaceProperties = networkInterface.GetIPProperties() įoreach (MulticastIPAddressInformation multicastIPAddressInformation in iPInterfaceProperties.MulticastAddresses) N.NetworkInterfaceType != NetworkInterfaceType.Loopback & n.OperationalStatus = OperationalStatus.Up)) Public static async Task WakeOnLan(string macAddress)īyte magicPacket = BuildMagicPacket(macAddress) įoreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces().Where((n) =>
REMOTE WAKE UP UBUNTU WIFI MAC
