PDA

View Full Version : ruby script for wakeonlan not working in 10.6




doobs
Oct 4, 2009, 01:59 PM
I have a WakeOnLan ruby script that I execute on my MacBook Pro in order to turn on a specific Ubuntu Linux machine on my LAN. This script worked under OS X 10.5, but no longer works on 10.6. Any ideas?

#!/usr/bin/env ruby

require 'socket'
include Socket::Constants

mac = 'XX:XX:XX:XX:XX:XX' #correct mac omitted for posting
ip = '255.255.255.255'

@magic ||= ("\xff" * 6)
mac_addr = mac.split(/:/).collect {|x| x.hex}.pack('CCCCCC')
@magic[6..-1] = (mac_addr * 16)
@ip_addr = ip
sock = UDPSocket.new
sock.setsockopt( SOL_SOCKET, SO_BROADCAST, 1 )
sock.connect( @ip_addr, Socket.getservbyname( 'discard', 'udp' ) )
sock.send( @magic, 0 )



jpyc7
Oct 5, 2009, 10:20 AM
I have a WakeOnLan ruby script that I execute on my MacBook Pro in order to turn on a specific Ubuntu Linux machine on my LAN. This script worked under OS X 10.5, but no longer works on 10.6. Any ideas?

#!/usr/bin/env ruby

require 'socket'
include Socket::Constants

mac = 'XX:XX:XX:XX:XX:XX' #correct mac omitted for posting
ip = '255.255.255.255'

@magic ||= ("\xff" * 6)
mac_addr = mac.split(/:/).collect {|x| x.hex}.pack('CCCCCC')
@magic[6..-1] = (mac_addr * 16)
@ip_addr = ip
sock = UDPSocket.new
sock.setsockopt( SOL_SOCKET, SO_BROADCAST, 1 )
sock.connect( @ip_addr, Socket.getservbyname( 'discard', 'udp' ) )
sock.send( @magic, 0 )


Have you tried debugging with something like tcpdump on either the Mac or the Linux box? That would confirm if you are sending/receiving packets as well as the contents of the packet (using the appropriate flags).

You might want to add some debug print statements to your script to see if it finishes correctly.