-
-
Save mraaroncruz/07d128d4d709f08b34060bbd27d169c4 to your computer and use it in GitHub Desktop.
A ruby script which sends out a magic packet to wake up your PC
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 | |
# wol.rb: sends out a magic packet to wake up your PC | |
# | |
# Copyright (c) 2004 zunda <zunda at freeshell.org> | |
# Modified by scharfie <scharfie at gmail dot com> | |
# | |
# This program is free software. You can re-distribute and/or | |
# modify this program under the same terms of ruby itself --- | |
# Ruby Distribution License or GNU General Public License. | |
# | |
require 'socket' | |
mac = '6C:F0:49:E3:DE:85' # hex numbers | |
network = '255.255.255.255' | |
local = true | |
port = 4343 | |
# message = "\xFF"*6 + [mac.gsub(/:/, '')].pack('H12')*16 | |
message = "\xFF".force_encoding(Encoding::ASCII_8BIT)*6 + [ mac.gsub( /:/, '' ) ].pack( 'H12' )*16 | |
txbytes = UDPSocket.open do |so| | |
so.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true) | |
so.send(message, 0, network, port) | |
end | |
puts "#{txbytes} bytes sent to #{network}:#{port}." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment