WakeOnLan

From AwkwardTV
Revision as of 00:48, 9 February 2010 by Matpol (talk | contribs) (New page: I spent A while trying find out how to get my Apple TV to wake up my server when it boots. It turns out that it is pretty straightforward. This assumes that you server is Wake on Lan enabl...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

I spent A while trying find out how to get my Apple TV to wake up my server when it boots. It turns out that it is pretty straightforward. This assumes that you server is Wake on Lan enabled.

1) First you need you need to follow the instructions on the wiki to install Python. This might seem complicated but if you follow them it will work.

2) You need to make a file somewhere on you PC and cut and paste this code into it:

import struct, socket

def wakeonlan(ethernet_address):

    1. construct a six-byte hardware address
  • addr_byte = ethernet_address.split(':')
  • hw_addr = struct.pack('bbbbbb', int(addr_byte[0], 16),
  • *int(addr_byte[1], 16),
  • *int(addr_byte[2], 16),
  • *int(addr_byte[3], 16),
  • *int(addr_byte[4], 16),
  • *int(addr_byte[5], 16))
    1. build the wake-on-lan "magic packet"...
  • msg = '\xff' * 6 + hw_addr * 16
    1. ...and send it to the broadcast address using udp
  • s = socket.socket(socket.af_inet, socket.sock_dgram)
  • s.setsockopt(socket.sol_socket, socket.so_broadcast, 1)
  • s.sendto(msg, ('<broadcast>', 7))
  • s.close()
  1. example use

wakeonlan('00:01:03:d8:7b:76')