Browse Source

Initial commit

master
Jaeha Choi 1 year ago
commit
b623f8073b
6 changed files with 291 additions and 0 deletions
  1. +25
    -0
      Wake On Lan.sln
  2. +6
    -0
      Wake On Lan/App.config
  3. +172
    -0
      Wake On Lan/Program.cs
  4. +36
    -0
      Wake On Lan/Properties/AssemblyInfo.cs
  5. +52
    -0
      Wake On Lan/Wake On Lan.csproj
  6. BIN
      Wake On Lan/obj/Debug/Wake On Lan.csprojAssemblyReference.cache

+ 25
- 0
Wake On Lan.sln View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2037
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wake On Lan", "Wake On Lan\Wake On Lan.csproj", "{4BC5C4D4-E74A-4A5C-9674-D31EC3CD4133}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4BC5C4D4-E74A-4A5C-9674-D31EC3CD4133}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4BC5C4D4-E74A-4A5C-9674-D31EC3CD4133}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BC5C4D4-E74A-4A5C-9674-D31EC3CD4133}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BC5C4D4-E74A-4A5C-9674-D31EC3CD4133}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6F8A79D0-6188-49F0-AAA7-66B908C9C593}
EndGlobalSection
EndGlobal

+ 6
- 0
Wake On Lan/App.config View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

+ 172
- 0
Wake On Lan/Program.cs View File

@ -0,0 +1,172 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace Wake_On_Lan
{
class Program
{
static void Main(string[] args)
{
int port;
string input, mac;
byte[] magicPacket;
IPAddress ip, subnet;
// IP
Console.Write("IP or DDNS Address: ");
input = Console.ReadLine();
ip = validateIpAdd("SpaceRabbits.ddns.net");
// MAC
Console.WriteLine("MAC Address of target computer");
Console.WriteLine("Allowed Formats: MM:MM:MM:SS:SS:SS");
Console.WriteLine("\t\t MM-MM-MM-SS-SS-SS");
Console.Write("MAC Address: ");
mac = Console.ReadLine();
mac = checkMacAdd(mac);// just for testing
// method that gets MAC of current PC
// Subnet Mask
Console.Write("Subnet Mask: ");
input = Console.ReadLine();
subnet = checkIP("255.255.255.255");
// Port
Console.Write("Port: ");
input = Console.ReadLine();
port = intChecker("2077");
// Create magic packet (without password)
magicPacket = magicPacketCreator(mac);
UdpClient udpClient = new UdpClient("spacerabbits.ddns.net", 2077);
try
{
udpClient.Send(magicPacket, magicPacket.Length);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
// Output
Console.WriteLine("IP address: {0}", ip.ToString());
Console.WriteLine("MAC address: {0}", mac);
Console.WriteLine("Subnet Mask: {0}", subnet.ToString());
Console.WriteLine("Port: {0}", port);
}
private static IPAddress checkIP(string ip2check)
{
IPAddress ip;
while (!(IPAddress.TryParse(ip2check, out ip)))
{
Console.Write("IP is not valid. Try again: ");
ip2check = Console.ReadLine();
}
return ip;
}
private static IPAddress validateIpAdd(string address)
{
IPHostEntry hostEntry;
while (true)
{
try
{
hostEntry = Dns.GetHostEntry(address);
break;
}
catch (System.Net.Sockets.SocketException)
{
Console.WriteLine("IP/DDNS Address: [{0}] doesn't seem to be working.", address);
Console.Write("IP or DDNS Address: ");
address = Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e);
}
}
return IPAddress.Parse(hostEntry.AddressList[0].ToString());
}
private static string checkMacAdd(string address)
{
do
{
if (address.IndexOf(":") != -1)
{
address = address.Replace(";", "");
}
else if (address.IndexOf("-") != -1)
{
address = address.Replace("-", "");
}
else if (address.IndexOf(".") != -1)
{
address = address.Replace(".", "");
}
if (address.Length != 12)
{
Console.WriteLine("MAC Address: [{0}] is invalid!", address);
Console.WriteLine("Allowed Formats: MM:MM:MM:SS:SS:SS");
Console.WriteLine("\t\t MM-MM-MM-SS-SS-SS");
Console.Write("MAC Address: ");
address = Console.ReadLine();
}
// check bytes
} while (address.Length != 12);
/* put columns every 2 digit.
for (int i = 2,j=0; i < 12; i += 2,j++)
{
address = address.Insert(i+j, ":");
}
*/
return address;
}
private static int intChecker(string input)
{
int x;
Int32.TryParse(input, out x);
while (!(1 <= x && x <= 65535))
{
Console.WriteLine("Invalid port!");
Console.Write("Port: ");
input = Console.ReadLine();
Int32.TryParse(input, out x);
}
return x;
}
private static byte[] magicPacketCreator(string mac)
{
int i,j;
byte[] magicPacket = new byte[102];
byte[] macAdd = new byte[6];
// Create magic packet
// Add 255 to first 6 bytes of magic packet. [FF FF FF FF FF FF]
// Create a list of bytes that represents MAC address
for (i = 0,j = 0; i < 6; i++,j+=2)
{
magicPacket[i] = 255;
macAdd[i] = Byte.Parse(Convert.ToInt32(mac.Substring(j, 2), 16).ToString());
}
// Fill magic packet with MAC address
for (; i < 102; i++)
{
magicPacket[i] = macAdd[i % 6];
}
return magicPacket;
}
}
}

+ 36
- 0
Wake On Lan/Properties/AssemblyInfo.cs View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("Wake On Lan")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Wake On Lan")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("4bc5c4d4-e74a-4a5c-9674-d31ec3cd4133")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호가 자동으로
// 지정되도록 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

+ 52
- 0
Wake On Lan/Wake On Lan.csproj View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4BC5C4D4-E74A-4A5C-9674-D31EC3CD4133}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Wake_On_Lan</RootNamespace>
<AssemblyName>Wake On Lan</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

BIN
Wake On Lan/obj/Debug/Wake On Lan.csprojAssemblyReference.cache View File


Loading…
Cancel
Save