Bitten Fleax Bitten Fleax - 1 year ago 54 Question

Can send normal UDP packet with - But how do you send a WOL packet?

I can send a packet with this:

Public Class Form1
Dim publisher As New Sockets.UdpClient(0)
Dim subscriber As New Sockets.UdpClient(2000)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
publisher.Connect(TBTo.Text, TBPort.Text)
Dim sendbytes() As Byte = ASCII.GetBytes("test")
publisher.Send(sendbytes, sendbytes.Length)
End Sub
End Class

It works great and using WireShark I can see on Port 9 a UDP Packet being sent to my IP (which I type into the address/word box).

I understand for WOL (Which I DO have working, just want to make my own application for fun/experience) you need a MAC, will it just "adding a MAC" address to this make it a WOL packet or is it more complicated than that?

NOTE: I can see the difference in WOL and UDP packets in Wireshark and changing my IP to "MYIP". For example below is a WOL packet sent from a WOL application.

40.000203000 MYIP WOL 144 MagicPacket for Micro-St_21:94:b6 (44:8a:5b:21:94:b6)

Compared to a normal UDP packet:

69 12170.303276000 MYIP UDP 46 Source port: 57465 Destination port: 9

I have played about A LOT with some examples but they are not the best.


I managed to do it after a few hours. If anyone else is stuck, here is how I did it:

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim MacAddress As String = "YOUR MAC ADDRESS HERE"
    Dim myAddress As String = "YOURIP HERE"
    Dim udpClient As New System.Net.Sockets.UdpClient

    Dim buf(101) As Char

    Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(buf)

    For x As Integer = 0 To 5

        sendBytes(x) = CByte("&HFF")


    Dim i As Integer = 6

    For x As Integer = 1 To 16

        sendBytes(i) = CByte("&H" + MacAddress.Substring(0, 2))

        sendBytes(i + 1) = CByte("&H" + MacAddress.Substring(2, 2))

        sendBytes(i + 2) = CByte("&H" + MacAddress.Substring(4, 2))

        sendBytes(i + 3) = CByte("&H" + MacAddress.Substring(6, 2))

        sendBytes(i + 4) = CByte("&H" + MacAddress.Substring(8, 2))

        sendBytes(i + 5) = CByte("&H" + MacAddress.Substring(10, 2))

        i += 6


    udpClient.Send(sendBytes, sendBytes.Length, myAddress, 9)
End Sub
End Class

That is it. Then all you do is change your IP and MAC to suit your needs. Or if you need, you can add in text boxes for different inputs.