Created
June 4, 2012 02:05
-
-
Save dgv/2865897 to your computer and use it in GitHub Desktop.
Ruby 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
#!/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