MintheWiki
요약
- 대기모드로 절전상태에 들어가 있는 PC를 네트웍카드를 통해 깨운다.
- 단 대기모드의 PC에 네트웍카드에 관련 세팅을 해줘야 합니다.
구성
- 해당PC 절전기능 및 매직패킷 WOL 세팅
- 공유기 UDP-40000 번 및 원격접속 100XX 포트 포워딩
소스
//Program.cs
using System;
using System.Net;
using System.Net.Sockets;
namespace WakeOnLan
{
class Program
{
static void Main(string[] args)
{
byte[] mac = new byte[] {0x00, 0x00, 0x00, 0x00, 0x6B, 0xE4};
WakeUp(mac);
}
/// <summary>
/// Sends a Wake-On-Lan packet to the specified MAC address.
/// </summary>
/// <param name="mac">Physical MAC address to send WOL packet to.</param>
private static void WakeUp(byte[] mac)
{
//
// WOL packet is sent over UDP 255.255.255.0:40000.
//
UdpClient client = new UdpClient();
client.Connect(IPAddress.Broadcast, 40000);
//
// WOL packet contains a 6-bytes trailer and 16 times a 6-bytes sequence containing the MAC address.
//
byte[] packet = new byte[17 * 6];
//
// Trailer of 6 times 0xFF.
//
for (int i = 0; i < 6; i++)
packet[i] = 0xFF;
//
// Body of magic packet contains 16 times the MAC address.
//
for (int i = 1; i <= 16; i++)
for (int j = 0; j < 6; j++)
packet[i * 6 + j] = mac[j];
//
// Submit WOL packet.
//
client.Send(packet, packet.Length);
}
}
}