Skip to content

Instantly share code, notes, and snippets.

@stevehodgkiss
Created April 20, 2012 00:47
Show Gist options
  • Save stevehodgkiss/2425073 to your computer and use it in GitHub Desktop.
Save stevehodgkiss/2425073 to your computer and use it in GitHub Desktop.
Command to send wake on lan packets
#!/usr/bin/env ruby
@mac = "xx:xx:xx:xx:xx:xx"
@address = "myaccount.dyndns.org"
@port = "9"
@count = 3
require 'socket'
@socket = UDPSocket.open
@socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1)
magicpacket = (0xff.chr)*6+(@mac.split(/:/).pack("H*H*H*H*H*H*"))*16
@count.times do
@socket.send(magicpacket, 0, @address, @port)
sleep 1
end
puts @count == 1 ? "Sending magic packet to #{@address}:#{@port} with #{@mac}" : "Sending magic packet to #{@address}:#{@port} with #{@mac} #{@count} times"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment