From 7dcf44f164e09b1182d95a905f7b8d71812911e4 Mon Sep 17 00:00:00 2001 From: Frost Date: Fri, 17 Nov 2023 09:19:20 -0600 Subject: [PATCH 1/4] Refresh code --- src/Program.cs | 5 +++-- src/WakeOnLan.cs | 36 ++++++++---------------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index ada8e45..b4fa821 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -12,8 +12,9 @@ static int Main(string[] args) while (true) // Continue prompting user until no more input is received { Console.Write("Enter MAC Address: "); - string mac = Console.ReadLine().Trim(); - if (mac == String.Empty) break; // User is done, exit + string mac = Console.ReadLine()?.Trim(); + if (string.IsNullOrEmpty(mac)) + break; // User is done, exit try { wol.Send(mac); diff --git a/src/WakeOnLan.cs b/src/WakeOnLan.cs index dc0d0ca..a1c80f0 100644 --- a/src/WakeOnLan.cs +++ b/src/WakeOnLan.cs @@ -3,13 +3,14 @@ using System.Net.Sockets; using System.Net.NetworkInformation; using System.Threading.Tasks; +using System.Collections.Generic; namespace WOLtool { public class WakeOnLan : IDisposable { private readonly Socket _sock; - private static readonly IPEndPoint[] _endpoints = new IPEndPoint[] + private static readonly IReadOnlyList _endpoints = new List { new IPEndPoint(IPAddress.Broadcast, 7), // echo new IPEndPoint(IPAddress.Broadcast, 9) // discard @@ -36,7 +37,7 @@ public void Send(string macAddress) } catch (Exception ex) { - throw new WakeOnLanException("ERROR broadcasting WakeOnLan Magic Packet.", ex); + throw new InvalidOperationException("ERROR broadcasting WakeOnLan Magic Packet.", ex); } } public void Send(PhysicalAddress macAddress) @@ -51,7 +52,7 @@ public void Send(PhysicalAddress macAddress) } catch (Exception ex) { - throw new WakeOnLanException("ERROR broadcasting WakeOnLan Magic Packet.", ex); + throw new InvalidOperationException("ERROR broadcasting WakeOnLan Magic Packet.", ex); } } @@ -68,7 +69,7 @@ public async Task SendAsync(string macAddress) } catch (Exception ex) { - throw new WakeOnLanException("ERROR broadcasting WakeOnLan Magic Packet.", ex); + throw new InvalidOperationException("ERROR broadcasting WakeOnLan Magic Packet.", ex); } } public async Task SendAsync(PhysicalAddress macAddress) @@ -83,7 +84,7 @@ public async Task SendAsync(PhysicalAddress macAddress) } catch (Exception ex) { - throw new WakeOnLanException("ERROR broadcasting WakeOnLan Magic Packet.", ex); + throw new InvalidOperationException("ERROR broadcasting WakeOnLan Magic Packet.", ex); } } @@ -102,7 +103,7 @@ private static byte[] BuildMagicPacket(PhysicalAddress macAddress) return magicPacket; // 102 Byte Magic Packet } - // Public implementation of Dispose pattern callable by consumers. + #region IDisposable private bool _disposed = false; public void Dispose() => Dispose(true); @@ -110,34 +111,13 @@ private static byte[] BuildMagicPacket(PhysicalAddress macAddress) protected virtual void Dispose(bool disposing) { if (_disposed) - { return; - } - if (disposing) { - // Dispose managed state (managed objects). _sock?.Dispose(); } - _disposed = true; } - } - - public class WakeOnLanException : Exception - { - public WakeOnLanException() - { - } - - public WakeOnLanException(string message) - : base(message) - { - } - - public WakeOnLanException(string message, Exception inner) - : base(message, inner) - { - } + #endregion } } From 9ebbe61c242bddf6c03cfa1dae4ef1d3b2c5596d Mon Sep 17 00:00:00 2001 From: Frost Date: Fri, 17 Nov 2023 09:19:35 -0600 Subject: [PATCH 2/4] Target .NET8 --- WOLtool.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WOLtool.csproj b/WOLtool.csproj index 33f0a67..b40d1d9 100644 --- a/WOLtool.csproj +++ b/WOLtool.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 none From 9a4ebb45fea15f92b82840df9f83679845b852de Mon Sep 17 00:00:00 2001 From: Frost Date: Fri, 17 Nov 2023 09:21:45 -0600 Subject: [PATCH 3/4] AOT Compile --- WOLtool.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/WOLtool.csproj b/WOLtool.csproj index b40d1d9..9fe2099 100644 --- a/WOLtool.csproj +++ b/WOLtool.csproj @@ -4,6 +4,7 @@ Exe net8.0 none + true From f0ece11a20619890d4a8c14ce2690cdde74c0b9c Mon Sep 17 00:00:00 2001 From: Frost <42287509+imerzan@users.noreply.github.com> Date: Fri, 17 Nov 2023 09:23:09 -0600 Subject: [PATCH 4/4] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 08c4204..3f72d73 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ # WOLtool -.NET Core Wake-On-Lan console utility. +.NET8 AOT Wake-On-Lan console utility. ## Instructions: 1) Make sure the remote computer has Wake-On-Lan enabled in the System BIOS, and the remote network adapter supports WOL and has it enabled. 2) Startup WOLtool, provide MAC Address of the remote computer's network card. - - Be sure you have the [.NET6](https://dotnet.microsoft.com/download) or newer runtime installed. - *(Optional)* You can run WOLtool from the command line: ```woltool ...``` Multiple MAC Addresses are supported. 3) If Magic Packet broadcast is successful, you will receive a 'OK' message. As long as the remote computer is properly configured, it should wake ([See Considerations](https://github.com/imerzan/WOLtool#considerations)).