Advertisement
Transfusion

wol.lua

Mar 29th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. function split(str, pat)
  2.    local t = {}
  3.    local fpat = "(.-)" .. pat
  4.    local last_end = 1
  5.    local s, e, cap = str:find(fpat, 1)
  6.    while s do
  7.       if s ~= 1 or cap ~= "" then
  8.      table.insert(t,cap)
  9.       end
  10.       last_end = e+1
  11.       s, e, cap = str:find(fpat, last_end)
  12.    end
  13.    if last_end <= #str then
  14.       cap = str:sub(last_end)
  15.       table.insert(t, cap)
  16.    end
  17.    return t
  18. end
  19.  
  20.  
  21. mac_dest = arg[1]
  22.  
  23. socket = require("socket")
  24. ip="255.255.255.255"
  25. port=9
  26. udp = assert(socket.udp())
  27. udp:setoption('broadcast', true)
  28.  
  29. mac_array=split(mac_dest, ":")
  30. mac = ""
  31. for i,v in ipairs(mac_array) do mac = mac..string.char(tonumber("0x"..v));  end
  32. mac1=""
  33. for i=1,16 do
  34.  mac1 = mac1..mac
  35. end
  36. mac2 = string.char(0xff,0xff,0xff,0xff,0xff,0xff)..mac1
  37. assert(udp:sendto(mac2, ip, port))
  38.  
  39. print("Wake-On-Lan packet sent to MAC address "..arg[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement