Last active
February 14, 2020 07:41
-
-
Save zunda/187139 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> | |
# | |
# 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. | |
# | |
# target machine | |
mac = 'XX:XX:XX:XX:XX:XX' # hex numbers | |
# target network | |
host = '192.168.X.X' | |
local = true | |
# host = 'example.com' | |
# local = false | |
require 'socket' | |
port = 9 # Discard Protocol | |
message = "\xFF".force_encoding(Encoding::ASCII_8BIT)*6 + [ mac.gsub( /:/, '' ) ].pack( 'H12' )*16 | |
txbytes = UDPSocket.open do |so| | |
if local then | |
so.setsockopt( Socket::SOL_SOCKET, Socket::SO_BROADCAST, true ) | |
end | |
so.send( message, 0, host, port ) | |
end | |
puts "#{txbytes} bytes sent to #{host}:#{port}." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment