Compare commits

..

5 Commits

  1. BIN
      WoL/Waker/Designcontest-Ecommerce-Business-Idea.ico
  2. 89
      WoL/Waker/MainForm.Designer.cs
  3. 194
      WoL/Waker/MainForm.cs
  4. 3
      WoL/Waker/MainForm.resx
  5. 8
      WoL/Waker/Properties/launchSettings.json
  6. 24
      WoL/Waker/Settings.Designer.cs
  7. 6
      WoL/Waker/Settings.settings
  8. 20
      WoL/Waker/Waker.csproj
  9. 79
      WoL/Waker/app.manifest
  10. 48
      WoL/WoL/PingCheck.cs
  11. 59
      WoL/WoL/Utils.cs
  12. 4
      WoL/WoL/WakeOnLan.csproj
  13. 16
      WoL/WoL/WoL.cs

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

@ -29,12 +29,20 @@ namespace Waker
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.AddressTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.MacTextBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.WakeButton = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.PortTextBox = new System.Windows.Forms.TextBox();
this.PingPortTextBox = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.PingStatusPanel = new System.Windows.Forms.Panel();
this.pingTimer = new System.Windows.Forms.Timer(this.components);
this.RECButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// AddressTextBox
@ -73,18 +81,82 @@ namespace Waker
//
this.WakeButton.Location = new System.Drawing.Point(271, 12);
this.WakeButton.Name = "WakeButton";
this.WakeButton.Size = new System.Drawing.Size(102, 54);
this.WakeButton.TabIndex = 2;
this.WakeButton.Size = new System.Drawing.Size(102, 83);
this.WakeButton.TabIndex = 4;
this.WakeButton.Text = "WoL";
this.WakeButton.UseVisualStyleBackColor = true;
this.WakeButton.Click += new System.EventHandler(this.WakeButton_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(19, 76);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(34, 15);
this.label3.TabIndex = 3;
this.label3.Text = "ports";
//
// PortTextBox
//
this.PortTextBox.Location = new System.Drawing.Point(67, 72);
this.PortTextBox.Name = "PortTextBox";
this.PortTextBox.Size = new System.Drawing.Size(198, 23);
this.PortTextBox.TabIndex = 2;
this.PortTextBox.Text = "7, 9";
//
// PingPortTextBox
//
this.PingPortTextBox.Location = new System.Drawing.Point(138, 101);
this.PingPortTextBox.Name = "PingPortTextBox";
this.PingPortTextBox.Size = new System.Drawing.Size(98, 23);
this.PingPortTextBox.TabIndex = 3;
this.PingPortTextBox.TextChanged += new System.EventHandler(this.PingPortTextBox_TextChanged);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(19, 105);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(113, 15);
this.label4.TabIndex = 3;
this.label4.Text = "ping port (optional)";
//
// PingStatusPanel
//
this.PingStatusPanel.BackColor = System.Drawing.Color.Gray;
this.PingStatusPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.PingStatusPanel.Location = new System.Drawing.Point(242, 101);
this.PingStatusPanel.Name = "PingStatusPanel";
this.PingStatusPanel.Size = new System.Drawing.Size(23, 23);
this.PingStatusPanel.TabIndex = 4;
//
// pingTimer
//
this.pingTimer.Interval = 5000;
this.pingTimer.Tick += new System.EventHandler(this.pingTimer_Tick);
//
// RECButton
//
this.RECButton.Location = new System.Drawing.Point(271, 101);
this.RECButton.Name = "RECButton";
this.RECButton.Size = new System.Drawing.Size(102, 23);
this.RECButton.TabIndex = 5;
this.RECButton.Text = "RD Client";
this.RECButton.UseVisualStyleBackColor = true;
this.RECButton.Click += new System.EventHandler(this.RECButton_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(383, 79);
this.ClientSize = new System.Drawing.Size(383, 134);
this.Controls.Add(this.RECButton);
this.Controls.Add(this.PingStatusPanel);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.PingPortTextBox);
this.Controls.Add(this.PortTextBox);
this.Controls.Add(this.WakeButton);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
@ -92,8 +164,8 @@ namespace Waker
this.Controls.Add(this.AddressTextBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximumSize = new System.Drawing.Size(399, 118);
this.MinimumSize = new System.Drawing.Size(399, 118);
this.MaximumSize = new System.Drawing.Size(399, 173);
this.MinimumSize = new System.Drawing.Size(399, 144);
this.Name = "MainForm";
this.Text = "Waker";
this.ResumeLayout(false);
@ -108,6 +180,13 @@ namespace Waker
private System.Windows.Forms.TextBox MacTextBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button WakeButton;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox PortTextBox;
private System.Windows.Forms.TextBox PingPortTextBox;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Panel PingStatusPanel;
private System.Windows.Forms.Timer pingTimer;
private System.Windows.Forms.Button RECButton;
}
}

@ -8,13 +8,27 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WakeOnLan;
using System.Configuration;
using System.Threading;
using System.Reflection;
using System.Security.Principal;
using System.Diagnostics;
using System.IO;
namespace Waker
{
public partial class MainForm : Form
{
private readonly Color PING_SUCCESS = Color.Green;
private readonly Color PING_FAIL = Color.Red;
private readonly Color PING_UNKNOWN = Color.Gray;
private string ip;
private string mac;
private string ports;
private string pingPort;
private Thread pingThread;
public MainForm()
{
@ -24,48 +38,206 @@ namespace Waker
private void InitInstance()
{
if (string.IsNullOrEmpty(Settings.Default.ip))
string path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
if (!string.IsNullOrEmpty(Settings.Default.ip))
ip = Settings.Default.ip;
if (string.IsNullOrEmpty(Settings.Default.mac))
if (!string.IsNullOrEmpty(Settings.Default.mac))
mac = Settings.Default.mac;
if (!string.IsNullOrEmpty(Settings.Default.ports))
ports = Settings.Default.ports;
if (!string.IsNullOrEmpty(Settings.Default.pingPort))
pingPort = Settings.Default.pingPort;
FillInformation();
AddressTextBox.TextChanged += AddressTextBox_TextChanged;
AddressTextBox.KeyUp += TextBox_KeyUp;
MacTextBox.KeyUp += TextBox_KeyUp;
PortTextBox.KeyUp += TextBox_KeyUp;
}
private void TextBox_KeyUp(object sender, KeyEventArgs e)
private void AddressTextBox_TextChanged(object sender, EventArgs e)
{
if (e.KeyCode != Keys.Enter)
return;
SetIp();
}
WakeButton_Click(sender, e);
private bool SetIp()
{
ip = AddressTextBox.Text.Replace(" ", "");
if (string.IsNullOrEmpty(ip))
return false;
AddressTextBox.Text = ip;
Settings.Default.ip = ip;
Settings.Default.Save();
return true;
}
private bool GetInformation()
private bool SetInformation()
{
ip = AddressTextBox.Text;
mac = MacTextBox.Text;
ip = AddressTextBox.Text.Replace(" ", "");
mac = MacTextBox.Text.Replace(" ", "");
ports = PortTextBox.Text.Replace(" ", "");
if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(mac))
return false;
AddressTextBox.Text = ip;
MacTextBox.Text = mac;
PortTextBox.Text = ports;
Settings.Default.ip = ip;
Settings.Default.mac = mac;
Settings.Default.ports = ports;
Settings.Default.Save();
return true;
}
private void FillInformation()
{
if (!string.IsNullOrEmpty(ip))
AddressTextBox.Text = ip;
if (!string.IsNullOrEmpty(mac))
MacTextBox.Text = mac;
if (!string.IsNullOrEmpty(ports))
PortTextBox.Text = ports;
if (!string.IsNullOrEmpty(pingPort))
PingPortTextBox.Text = pingPort;
}
private void WakeButton_Click(object sender, EventArgs e)
{
if (!GetInformation())
if (!SetInformation())
{
MessageBox.Show("Invalid information");
return;
}
WoL.Wake(ip, mac);
try
{
string portsString = ports.Replace(" ", "");
if (string.IsNullOrEmpty(portsString))
{
WoL.Wake(ip, mac);
return;
}
string[] portStringArray = portsString.Split(',');
if (portStringArray == null || portStringArray.Length < 1 || string.IsNullOrEmpty(portStringArray[0]))
{
WoL.Wake(ip, mac);
return;
}
int[] portArray = portStringArray.Select(int.Parse).ToArray();
if (portArray == null || portArray.Length< 1)
{
WoL.Wake(ip, mac);
return;
}
WoL.Wake(ip, mac, portArray);
} catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void TextBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode != Keys.Enter)
return;
WakeButton_Click(sender, e);
}
private void PingPortTextBox_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(PingPortTextBox.Text))
return;
pingPort = PingPortTextBox.Text;
if (!pingTimer.Enabled)
pingTimer.Enabled = true;
}
private void pingTimer_Tick(object sender, EventArgs e)
{
try
{
int targetPort = 0;
if (!int.TryParse(pingPort, out targetPort))
{
PingStatusPanel.BackColor = PING_UNKNOWN;
return;
}
if (targetPort < 1)
{
PingStatusPanel.BackColor = PING_UNKNOWN;
return;
}
if (string.IsNullOrEmpty(ip))
return;
Settings.Default.pingPort = pingPort;
Settings.Default.Save();
object[] parameters = new object[2] { ip, targetPort };
pingThread = new Thread(new ParameterizedThreadStart(SendPing));
pingThread.Start(parameters);
} catch (Exception ex)
{
pingTimer.Enabled = false;
MessageBox.Show(ex.Message);
}
}
public void SendPing(object parameters)
{
object[] src = parameters as object[];
if (src == null || src.Length < 2)
return;
string ip = src[0] as string;
int? port = src[1] as int?;
if (ip == null || port == null)
return;
if (PingCheck.Test(ip, port == null ? default(int) : port.Value))
{
PingStatusPanel.BackColor = PING_SUCCESS;
}
else
PingStatusPanel.BackColor = PING_FAIL;
}
private void RECButton_Click(object sender, EventArgs e)
{
string path = @"C:\Windows\System32\mstsc.exe";
if (!File.Exists(path))
return;
Process.Start(path);
}
}
}

@ -57,6 +57,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="pingTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

@ -0,0 +1,8 @@
{
"profiles": {
"Waker": {
"commandName": "Project",
"remoteDebugEnabled": false
}
}
}

@ -46,5 +46,29 @@ namespace Waker {
this["mac"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("7, 9")]
public string ports {
get {
return ((string)(this["ports"]));
}
set {
this["ports"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string pingPort {
get {
return ((string)(this["pingPort"]));
}
set {
this["pingPort"] = value;
}
}
}
}

@ -8,5 +8,11 @@
<Setting Name="mac" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ports" Type="System.String" Scope="User">
<Value Profile="(Default)">7, 9</Value>
</Setting>
<Setting Name="pingPort" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

@ -4,8 +4,24 @@
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<AssemblyVersion>1.0.0.1</AssemblyVersion>
<StartupObject>Waker.Program</StartupObject>
<ApplicationIcon>Designcontest-Ecommerce-Business-Idea.ico</ApplicationIcon>
<Version>1.0.0.1</Version>
<PackageIcon>Designcontest-Ecommerce-Business-Idea.ico</PackageIcon>
<PackageIconUrl />
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Content Include="Designcontest-Ecommerce-Business-Idea.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WoL\WakeOnLan.csproj" />
</ItemGroup>
@ -23,6 +39,10 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Include="..\..\Resource\Designcontest-Ecommerce-Business-Idea.ico">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 매니페스트 옵션
Windows 사용자 계정 컨트롤 수준을 변경하려면
requestedExecutionLevel 노드를 다음 중 하나로 바꿉니다.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
requestedExecutionLevel 요소를 지정하면 파일 및 레지스트리 가상화를 사용하지 않습니다.
이전 버전과의 호환성을 위해 애플리케이션에 가상화가 필요한 경우
이 요소를 제거합니다.
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 이 애플리케이션이 테스트되고 함께 작동하도록 설계된 Windows 버전
목록입니다. 해당 요소의 주석 처리를 제거하면 Windows에서
호환 가능성이 가장 큰 환경을 자동으로 선택합니다. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- 애플리케이션이 DPI를 인식하며 높은 DPI에서 Windows가 자동으로 스케일링하지
않음을 나타냅니다. WPF(Windows Presentation Foundation) 애플리케이션은 자동으로 DPI를 인식하며
옵트인할 필요가 없습니다. 이 설정에 옵트인한 .NET Framework 4.6을 대상으로 하는
Windows Forms 애플리케이션은 app.config에서 'EnableWindowsFormsHighDpiAutoResizing' 설정도 'true'로 설정해야 합니다.
애플리케이션이 긴 경로를 인식하도록 설정합니다. https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation을 참조하세요. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->
<!-- Windows 공용 컨트롤 및 대화 상자의 테마 사용(Windows XP 이상) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
namespace WakeOnLan
{
public class PingCheck
{
public static bool Test(string ip, int port, int timeout = 5 * 1000)
{
Socket socket = null;
try
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, false);
IAsyncResult result = socket.BeginConnect(ip, port, null, null);
return result.AsyncWaitHandle.WaitOne(timeout, true);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (socket != null)
socket.Close();
}
//Ping ping = new Ping();
//PingOptions options = new PingOptions();
//options.DontFragment = true;
//string data = "123123123";
//byte[] buffer = ASCIIEncoding.ASCII.GetBytes(data);
//PingReply reply = ping.Send(ipAddress, , timeout, buffer);
//if (reply.Status == IPStatus.Success)
// return true;
//return false;
}
}
}

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Security.Principal;
namespace WakeOnLan
{
public class Utils
{
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
public static IPAddress GetIpAddress(string ip)
{
Regex regex = new Regex(@"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$");
if (regex.IsMatch(ip))
return IPAddress.Parse(ip);
IPHostEntry hostEntry = Dns.GetHostEntry(ip);
if (hostEntry.AddressList.Length < 1)
throw new Exception("invalid ip address");
return hostEntry.AddressList[0];
}
public static void SysTest()
{
IntPtr wow64Value = IntPtr.Zero;
File.Create(@"c:\windows\system32\test");
Debug.WriteLine("Default System Directory : {0}", File.Exists(@"c:\windows\system32\test"));
//Disable Redirection
Wow64DisableWow64FsRedirection(ref wow64Value);
Debug.WriteLine("Wow64Redirection Disable : {0}", File.Exists(@"c:\windows\system32\test"));
//Enable Redirection
Wow64RevertWow64FsRedirection(wow64Value);
Debug.WriteLine("Wow64Redirection Enable : {0}", File.Exists(@"c:\windows\system32\test"));
}
public static bool IsRunningAsAdmin()
{
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity);
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
}

@ -4,4 +4,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
</ItemGroup>
</Project>

@ -9,18 +9,24 @@ namespace WakeOnLan
{
public class WoL
{
private const int WOL_PACKET_LEN = 102;
private static readonly int WOL_PACKET_LEN = 102;
private static readonly int[] DEFAULT_PORTS = new int[] { 7, 9 };
public static void Wake(string ip, string macAddress)
public static void Wake(string ip, string macAddress, int[] ports = null)
{
byte[] wolBuffer = GetWolPacket(macAddress);
UdpClient udp = new UdpClient();
udp.EnableBroadcast = true;
IPAddress ipAddress = IPAddress.Parse(ip);
udp.Send(wolBuffer, wolBuffer.Length, ipAddress.ToString(), 7);
udp.Send(wolBuffer, wolBuffer.Length, ipAddress.ToString(), 9);
IPAddress ipAddress = Utils.GetIpAddress(ip);
if (ports == null || ports.Length < 1)
ports = DEFAULT_PORTS;
foreach (int port in ports)
{
udp.Send(wolBuffer, wolBuffer.Length, ipAddress.ToString(), port);
}
}
private static byte[] GetWolPacket(string macAddress)

Loading…
Cancel
Save