LogicMachine Forum
Simple Wake-on-lan - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Simple Wake-on-lan (/showthread.php?tid=849)



Simple Wake-on-lan - Matt - 19.06.2017

Hello,

The wake-on-lan code I am using.

Code:
--[[ Librairy : Wake-on-lan Author : Matthieu Bouthors Use with mac address example : WOL("4c-cc-6a-03-55-eb") Reminder : only works if the destination is on the same subnet, not routable ]]-- function WOL(target)  local socket = require("socket")  local dest_ip="255.255.255.255"  local port=9  local udp = assert(socket.udp())  udp:setoption('broadcast', true)    clean_target = string.gsub(target,":","")  clean_target = string.gsub(clean_target,"-","")  hex_target = lmcore.hextostr(clean_target)  payload = lmcore.hextostr("FFFFFFFFFFFF")  for i=1,16 do    payload = payload .. hex_target  end    assert(udp:sendto(payload, dest_ip, port)) end

Matt


RE: Simple Wake-on-lan - leonidas - 21.06.2017

one more:

Code:
function wol_send(mac_dest)  local mac = ''  for w in string.gmatch(mac_dest, "[0-9A-Za-z][0-9A-Za-z]") do    mac = mac .. string.char(tonumber(w, 16))  end  local udp = require("socket").udp()  udp:settimeout(1)  udp:setoption("broadcast", true)  udp:sendto(string.char(0xff):rep(6) .. mac:rep(16) , '255.255.255.255', 9)   end