-
-
Save kryptek/54488ce89ac4437c41d2 to your computer and use it in GitHub Desktop.
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) | |
mac_address = ARGV[0] | |
mac_address = mac_address.split(':').map(&:hex).map(&:chr).join('') * 16 | |
data = "\xFF" * 6 | |
data = "#{data}#{mac_address}" | |
puts "Wake-On-Lan packet send to MAC address #{ARGV[0]}" | |
UDPSock.send(data, 0, '<broadcast>', 9) | |
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