fix: message
This commit is contained in:
parent
b95aa2c554
commit
1a0a51e960
@ -21,14 +21,13 @@ namespace WakeOnLan
|
|||||||
Send(IPAddress.Broadcast, 9, macAddr);
|
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(':');
|
string[] macTmp = macAddr.Split(':');
|
||||||
|
|
||||||
if (macTmp.Length != 6)
|
if (macTmp.Length != 6)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Macアドレスが正しくありません。");
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] mac = new byte[6];
|
byte[] mac = new byte[6];
|
||||||
@ -38,10 +37,10 @@ namespace WakeOnLan
|
|||||||
mac[i] = Convert.ToByte(macTmp[i], 16);
|
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())
|
using (MemoryStream stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -64,6 +63,8 @@ namespace WakeOnLan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,18 +9,26 @@ namespace WakeOnLan
|
|||||||
{
|
{
|
||||||
Network network = new Network();
|
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(':');
|
string[] macTmp = macAddr.Split(':');
|
||||||
|
|
||||||
if (macTmp.Length != 6)
|
if (macTmp.Length != 6)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Macアドレスが正しくありません。");
|
Console.WriteLine("Invalid MAC Address");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,9 +39,23 @@ namespace WakeOnLan
|
|||||||
mac[i] = Convert.ToByte(macTmp[i], 16);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<AssemblyName>wol</AssemblyName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
Loading…
Reference in New Issue
Block a user