Does this look good?Code:Public Shared Sub WOL(ByVal targetMAC() As Byte, ByVal password() As Byte) ' target mac must be 6-bytes! If (targetMAC.Length <> 6) Then Throw New ArgumentException End If ' check password If ((Not (password) Is Nothing) _ AndAlso ((password.Length <> 4) _ AndAlso (password.Length <> 6))) Then Throw New ArgumentException End If Dim packetLength As Integer = (6 + (20 * 6)) If (Not (password) Is Nothing) Then packetLength = (packetLength + password.Length) End If Dim magicPacket() As Byte = New Byte((packetLength) - 1) {} ' has a 6-byte header of 0xFF Dim header() As Byte = New Byte() {255, 255, 255, 255, 255, 255} Buffer.BlockCopy(header, 0, magicPacket, 0, header.Length) ' repeat the destination MAC 16 times ' your MAC *is* in network (reverse) order, right?? Dim offset As Integer = 6 Dim i As Integer = 0 Do While (i < 16) Buffer.BlockCopy(targetMAC, 0, magicPacket, offset, targetMAC.Length) offset = (offset + 6) i = (i + 1) Loop If (Not (password) Is Nothing) Then Buffer.BlockCopy(password, 0, magicPacket, offset, password.Length) End If Dim ep As IPEndPoint = New IPEndPoint(IPAddress.Broadcast, 9) Dim c As UdpClient = New UdpClient c.Send(magicPacket, magicPacket.Length, ep) End Sub
However, I am bit confused as to how to format the MAC Adress when calling the sub..
WOL("00-1B-FC-CB-49-6B") wont work because its not supposed to be a string. Do I have to convert the MAC from Hex to Binary..or?




Reply With Quote
