Created
June 4, 2012 00:01
-
-
Save filewalkwithme/2865500 to your computer and use it in GitHub Desktop.
Lua Wake-On-Lan Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function split(str, pat) | |
local t = {} | |
local fpat = "(.-)" .. pat | |
local last_end = 1 | |
local s, e, cap = str:find(fpat, 1) | |
while s do | |
if s ~= 1 or cap ~= "" then | |
table.insert(t,cap) | |
end | |
last_end = e+1 | |
s, e, cap = str:find(fpat, last_end) | |
end | |
if last_end <= #str then | |
cap = str:sub(last_end) | |
table.insert(t, cap) | |
end | |
return t | |
end | |
mac_dest = arg[1] | |
socket = require("socket") | |
ip="255.255.255.255" | |
port=9 | |
udp = assert(socket.udp()) | |
udp:setoption('broadcast', true) | |
mac_array=split(mac_dest, ":") | |
mac = "" | |
for i,v in ipairs(mac_array) do mac = mac..string.char(tonumber("0x"..v)); end | |
mac1="" | |
for i=1,16 do | |
mac1 = mac1..mac | |
end | |
mac2 = string.char(0xff,0xff,0xff,0xff,0xff,0xff)..mac1 | |
assert(udp:sendto(mac2, ip, port)) | |
print("Wake-On-Lan packet sent to MAC address "..arg[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script sends an Wake-On-Lan magic packet to a given target Mac Address. If everything succeed, the target machine should power on.
Usage:
$ lua wol.lua AA:BB:CC:DD:EE:FF
Wake-On-Lan sent to MAC address AA:BB:CC:DD:EE:FF