Sie sind auf Seite 1von 1

Imports System.Net.

Sockets 'we derive our class from a standart one Public Class WOLClass Inherits UdpClient Public Sub New() MyBase.New() End Sub 'this is needed to send broadcast packet Public Sub SetClientToBrodcastMode() If Me.Active Then Me.Client.SetSocketOption(SocketOptionLevel.Socket, Sock etOptionName.Broadcast, 0) End If End Sub End Class ... 'now use this class 'MAC_ADDRESS should look like '013FA049' Private Sub WakeFunction(MAC_ADDRESS As String) Dim client As New WOLClass() '255.255.255.255 i.e broadcast client.Connect(New IPAddress(&HffffffffUI), &H2fff) ' port=12287 let's use this one client.SetClientToBrodcastMode() 'set sending bites Dim counter As Integer = 0 'buffer to be send Dim bytes As Byte() = New Byte(1023) {} ' more than enough :-) 'first 6 bytes should be 0xFF For y As Integer = 0 To 5 bytes(System.Math.Max(System.Threading.Interlocked.Increment(cou nter),counter - 1)) = &Hff Next 'now repeate MAC 16 times For y As Integer = 0 To 15 Dim i As Integer = 0 For z As Integer = 0 To 5 bytes(System.Math.Max(System.Threading.Interlocked.Incre ment(counter),counter - 1)) = Byte.Parse(MAC_ADDRESS.Substring(i, 2), NumberStyl es.HexNumber) i += 2 Next Next 'now send wake up packet Dim reterned_value As Integer = client.Send(bytes, 1024) End Sub

Das könnte Ihnen auch gefallen