Skip to content

Instantly share code, notes, and snippets.

@dgv
Created June 4, 2012 02:05
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dgv/2865897 to your computer and use it in GitHub Desktop.
Ruby Wake-On-Lan Script
#!/usr/bin/ruby
require 'socket'
begin
addr = ['<broadcast>', 9]
UDPSock = UDPSocket.new
UDPSock.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
data = "\xFF\xFF\xFF\xFF\xFF\xFF"
arr = ARGV[0].split(':')
16.times do |i|
data<< arr[0].hex.chr+arr[1].hex.chr+arr[2].hex.chr+arr[3].hex.chr+arr[4].hex.chr+arr[5].hex.chr
end
puts("Wake-On-Lan packet sent to MAC address "+ARGV[0])
UDPSock.send(data, 0, addr[0], addr[1])
rescue
puts("usage: sample_wol.rb <mac-address>")
puts(" sample_wol.rb 01:02:03:04:05:06")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment