From e0be19ce076c86948e51c5dd257442b3b971557e Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Fri, 27 Nov 2020 01:05:44 +0200 Subject: [PATCH] Removed old NetworkResurrector.WakeOnLan project --- .../DependencyInjectionExtensions.cs | 14 --- .../NetworkResurrector.WakeOnLan.csproj | 16 ---- NetworkResurrector.WakeOnLan/WolClient.cs | 45 --------- NetworkResurrector.WakeOnLan/WolDriver.cs | 92 ------------------- NetworkResurrector.sln | 6 -- 5 files changed, 173 deletions(-) delete mode 100644 NetworkResurrector.WakeOnLan/DependencyInjectionExtensions.cs delete mode 100644 NetworkResurrector.WakeOnLan/NetworkResurrector.WakeOnLan.csproj delete mode 100644 NetworkResurrector.WakeOnLan/WolClient.cs delete mode 100644 NetworkResurrector.WakeOnLan/WolDriver.cs diff --git a/NetworkResurrector.WakeOnLan/DependencyInjectionExtensions.cs b/NetworkResurrector.WakeOnLan/DependencyInjectionExtensions.cs deleted file mode 100644 index 87ea4fa..0000000 --- a/NetworkResurrector.WakeOnLan/DependencyInjectionExtensions.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using NetworkResurrector.Abstractions; - -namespace NetworkResurrector.WakeOnLan -{ - public static class DependencyInjectionExtensions - { - public static void AddWakeOnLanService(this IServiceCollection services) - { - services.AddScoped(); - services.AddScoped(); - } - } -} diff --git a/NetworkResurrector.WakeOnLan/NetworkResurrector.WakeOnLan.csproj b/NetworkResurrector.WakeOnLan/NetworkResurrector.WakeOnLan.csproj deleted file mode 100644 index a0dc859..0000000 --- a/NetworkResurrector.WakeOnLan/NetworkResurrector.WakeOnLan.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - netstandard2.0 - - - - - - - - - - - - diff --git a/NetworkResurrector.WakeOnLan/WolClient.cs b/NetworkResurrector.WakeOnLan/WolClient.cs deleted file mode 100644 index b6c34f1..0000000 --- a/NetworkResurrector.WakeOnLan/WolClient.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Net.Sockets; - -namespace NetworkResurrector.WakeOnLan -{ - internal class WolClient : UdpClient - { - private readonly ILogger _logger; - - /// - /// Initializes a new instance of . - /// - public WolClient(ILogger logger) : base() - { - _logger = logger; - } - - /// - /// Sets up the UDP client to broadcast packets. - /// - /// if the UDP client is set in - /// broadcast mode. - public bool SetClientInBrodcastMode() - { - bool broadcast = false; - if (this.Active) - { - try - { - this.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 0); - _logger.LogInformation("WolClient => SetClientInBrodcastMode succedded."); - broadcast = true; - } - catch(Exception ex) - { - broadcast = false; - _logger.LogError("WolClient => SetClientInBrodcastMode failed.", ex); - } - } - - return broadcast; - } - } -} diff --git a/NetworkResurrector.WakeOnLan/WolDriver.cs b/NetworkResurrector.WakeOnLan/WolDriver.cs deleted file mode 100644 index 019bf63..0000000 --- a/NetworkResurrector.WakeOnLan/WolDriver.cs +++ /dev/null @@ -1,92 +0,0 @@ -using NetworkResurrector.Abstractions; -using System.Globalization; -using System.Net; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -namespace NetworkResurrector.WakeOnLan -{ - internal class WolDriver : IWakeOnLanService - { - private readonly WolClient _client; - - public WolDriver(WolClient client) - { - _client = client; - } - - public async Task<(bool success, string message)> Wake(string macAddress) - { - //remove all non 0-9, A-F, a-f characters - macAddress = Regex.Replace(macAddress, @"[^0-9A-Fa-f]", ""); - - //check if mac adress length is valid - if (macAddress.Length != 12) - return (false, "Invalid MAC address."); - else - return await Wakeup(macAddress); - } - - #region Wakeup - /// - /// Wakes up the machine with the given . - /// - /// - /// - /// - /// - /// The motherboard must support Wake On LAN. - /// The NIC must support Wake On LAN. - /// There must be a wire connecting the motherboard's WOL port to - /// the NIC's WOL port. Usually there always is a connection on most of - /// the PCs. - /// The Wake On LAN feature must be enabled in the motherboard's - /// BIOS. Usually this is also enabled by default, but you might like to - /// check again. - /// The "Good Connection" light on the back of the NIC must be lit - /// when the machine is off. (By default always good if you are not - /// facing any network issues) - /// Port 12287 (0x2FFF) must be open. (By default it should be - /// open unless some antivirus or any other such program has changed - /// settings.) - /// Packets cannot be broadcast across the Internet.  That's why - /// it's called Wake On Lan, not Wake On Internet. - /// To find your MAC address, run the MSINFO32.EXE tool that is a - /// part of Windows and navigate to Components > Network > Adapter - /// or simply type nbtstat -a <your hostname < at command prompt. - /// e.g. nbtstat -a mymachinename or nbtstat -A 10.2.100.213. - /// The MAC address of the host which has to be - /// woken up. - /// - private async Task<(bool success, string message)> Wakeup(string macAddress) - { - _client.Connect(new IPAddress(0xffffffff) /*255.255.255.255  i.e broadcast*/, 0x2fff /*port = 12287*/); - - if (!_client.SetClientInBrodcastMode()) - return (false, "Remote client could not be set in broadcast mode!"); - - int byteCount = 0; - byte[] bytes = new byte[102]; - - for (int trailer = 0; trailer < 6; trailer++) - { - bytes[byteCount++] = 0xFF; - } - - for (int macPackets = 0; macPackets < 16; macPackets++) - { - int i = 0; - for (int macBytes = 0; macBytes < 6; macBytes++) - { - bytes[byteCount++] = byte.Parse(macAddress.Substring(i, 2), NumberStyles.HexNumber); - i += 2; - } - } - - int returnValue = await _client.SendAsync(bytes, byteCount); - - return (true, $"{returnValue} bytes sent to {macAddress}"); - } - #endregion - } -} diff --git a/NetworkResurrector.sln b/NetworkResurrector.sln index ec57d48..1d25b3c 100644 --- a/NetworkResurrector.sln +++ b/NetworkResurrector.sln @@ -18,8 +18,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Applicat EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Domain", "NetworkResurrector.Domain\NetworkResurrector.Domain.csproj", "{EC78E88E-22DC-4FFD-881E-DEECF0D2494E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.WakeOnLan", "NetworkResurrector.WakeOnLan\NetworkResurrector.WakeOnLan.csproj", "{A7B3FCE1-70F5-4EAE-A8FB-EF938AE1D105}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Abstractions", "NetworkResurrector.Abstractions\NetworkResurrector.Abstractions.csproj", "{B7408385-ED73-4ED3-9654-9AFF8CDFDA8D}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.WakeOnLan.Nikeee", "NetworkResurrector.WakeOnLan.Nikeee\NetworkResurrector.WakeOnLan.Nikeee.csproj", "{59049C2B-CEFB-456D-B3D5-D2CF5325AEEB}" @@ -44,10 +42,6 @@ Global {EC78E88E-22DC-4FFD-881E-DEECF0D2494E}.Debug|Any CPU.Build.0 = Debug|Any CPU {EC78E88E-22DC-4FFD-881E-DEECF0D2494E}.Release|Any CPU.ActiveCfg = Release|Any CPU {EC78E88E-22DC-4FFD-881E-DEECF0D2494E}.Release|Any CPU.Build.0 = Release|Any CPU - {A7B3FCE1-70F5-4EAE-A8FB-EF938AE1D105}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A7B3FCE1-70F5-4EAE-A8FB-EF938AE1D105}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A7B3FCE1-70F5-4EAE-A8FB-EF938AE1D105}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A7B3FCE1-70F5-4EAE-A8FB-EF938AE1D105}.Release|Any CPU.Build.0 = Release|Any CPU {B7408385-ED73-4ED3-9654-9AFF8CDFDA8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B7408385-ED73-4ED3-9654-9AFF8CDFDA8D}.Debug|Any CPU.Build.0 = Debug|Any CPU {B7408385-ED73-4ED3-9654-9AFF8CDFDA8D}.Release|Any CPU.ActiveCfg = Release|Any CPU