Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1549 | Anzahl registrierter User: 1833 | Besucher online: 1193
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

Wake on LAN


Autor: Gast
Sprache: C#
Bewertung:
9.62 (3 votes)
Anzahl der Aufrufe: 16000
  
Kick it on dotnet-kicks.de  

Beschreibung:

Wake on LAN in C#

Beispielaufruf für die Mac Adresse 00:30:84:79:AA:E3

byte[] macaddress = new byte[] {0x00, 0x30, 0x84, 0x79, 0xAA, 0xE3};
WakeOnLan(macaddress);

Benötigte Namespaces:

using System;
using System.Net;
using System.Net.Sockets;


Abgelegt unter: Magic packet, MAC, Wake on LAN, Lan, WOL.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/// <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 WakeOnLan(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];

    // Send WOL packet.
    client.Send(packet, packet.Length);
}
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.