-->
Page 1 of 1

Wake-On-LAN example to a PC

PostPosted: Sat May 09, 2015 10:00 am
by tertius
Hi

Just thought I'd share a WOL implementation, used to boot a PC over the local LAN. Its based on the code found here: https://gist.github.com/maiconio/2865500

Note that your target machine needs to be setup to accept this packet. Typically this calls for both a BIOS and network adapter settings change (the latter is in your operating system / device manager, etc.). Google is helpful to get this setup.

Code: Select allwolcon=net.createConnection(net.UDP, 0) --Not tested with TCP. UDP works fine
wolcon:connect(9,"255.255.255.255") --Magic packet is broadcast. Can also limit to broadcast address of your own network

mac1=string.char(0xe0,0x69,0x95,0xab,0x36,0xe7) -- Insert MAC address here of target machine
for i=1,4 do
 mac1 = mac1..mac1  --Magic packet requires 16x target PC MAC as payload
end

mac2 = string.char(0xff,0xff,0xff,0xff,0xff,0xff)..mac1 --Magic packet needs broadcast MAC in front
wolcon:send(mac2)   --Send magic packet
print("Wake-On-Lan packet sent")

wolcon:close()
collectgarbage();


Enjoy!

Re: Wake-On-LAN example to a PC

PostPosted: Sat May 09, 2015 11:57 am
by cal
Cool!

Thanks for sharing!

Cal

Re: Wake-On-LAN example to a PC

PostPosted: Fri Jun 26, 2020 5:47 am
by Thomas Jakober
Thanks for the tip! :D I just modified it for use with Nodemcu 3.0.0.0 onwards:

Code: Select allwolcon=net.createUDPSocket() --Not tested with TCP. UDP works fine

mac1=string.char(0xa4,0x5d,0x36,0xbc,0x2c,0x5d) -- Insert MAC address here of target machine
for i=1,4 do
 mac1 = mac1..mac1  --Magic packet requires 16x target PC MAC as payload
end

mac2 = string.char(0xff,0xff,0xff,0xff,0xff,0xff)..mac1 --Magic packet needs broadcast MAC in front
wolcon:send(9, "255.255.255.255", mac2)   --Send magic packet
print("Wake-On-Lan packet sent")

wolcon:close()
collectgarbage();