diff --git a/WakeOnLan/Network.cs b/WakeOnLan/Network.cs index 7be52df..c116b56 100644 --- a/WakeOnLan/Network.cs +++ b/WakeOnLan/Network.cs @@ -21,14 +21,13 @@ namespace WakeOnLan Send(IPAddress.Broadcast, 9, macAddr); } - public void Send(IPAddress ipAddr, int port, string macAddr) + public bool Send(IPAddress ipAddr, int port, string macAddr) { string[] macTmp = macAddr.Split(':'); if (macTmp.Length != 6) { - Console.WriteLine("Macアドレスが正しくありません。"); - return; + return false; } byte[] mac = new byte[6]; @@ -38,10 +37,10 @@ namespace WakeOnLan mac[i] = Convert.ToByte(macTmp[i], 16); } - Send(ipAddr, port, mac); + return Send(ipAddr, port, mac); } - public void Send(IPAddress ipAddr, int port, byte[] macAddress) + public bool Send(IPAddress ipAddr, int port, byte[] macAddress) { using (MemoryStream stream = new MemoryStream()) { @@ -64,6 +63,8 @@ namespace WakeOnLan } } } + + return true; } } } diff --git a/WakeOnLan/Program.cs b/WakeOnLan/Program.cs index 8f105e3..d7c2282 100644 --- a/WakeOnLan/Program.cs +++ b/WakeOnLan/Program.cs @@ -9,18 +9,26 @@ namespace WakeOnLan { Network network = new Network(); - string macAddr = "80:65:7c:d3:c0:ea"; + string macAddr = ""; - if (args.Length > 0) + if ( args.Length == 0) { - macAddr = args[0]; + Console.WriteLine("Copyright (c) 2022 DevRas All Rights Reserved."); + Console.WriteLine("WOL Tool"); + Console.WriteLine(""); + Console.WriteLine("$ wol [MAC-Address]"); + Console.WriteLine(" e.g. MAC-Address: FF:FF:FF:FF:FF:FF"); + Console.WriteLine("$ wol FF:FF:FF:FF:FF:FF"); + return; } + macAddr = args[0].ToUpper(); + string[] macTmp = macAddr.Split(':'); if (macTmp.Length != 6) { - Console.WriteLine("Macアドレスが正しくありません。"); + Console.WriteLine("Invalid MAC Address"); return; } @@ -31,9 +39,23 @@ namespace WakeOnLan mac[i] = Convert.ToByte(macTmp[i], 16); } - network.Send(IPAddress.Broadcast, 9, mac); + try + { + bool result = network.Send(IPAddress.Broadcast, 9, mac); - Console.WriteLine("WOL: Target {0}, To {1}", macAddr, IPAddress.Broadcast); + if (!result) + { + Console.WriteLine("WOL Error: Can not send magic packet."); + return; + } + + Console.WriteLine("WOL To : {0}", IPAddress.Broadcast); + Console.WriteLine("WOL Target : {0}", macAddr); + } + catch (Exception ex) + { + Console.WriteLine("WOL Network Error:" + ex.Message); + } } } } diff --git a/WakeOnLan/WakeOnLan.csproj b/WakeOnLan/WakeOnLan.csproj index 325a08f..43c53b1 100644 --- a/WakeOnLan/WakeOnLan.csproj +++ b/WakeOnLan/WakeOnLan.csproj @@ -3,6 +3,7 @@ Exe netcoreapp3.1 + wol