Network을 통해서 원격지에 있는 컴퓨터를 켜는 것.
WakeOnLan을 할수 있으려면 랜카드가 항상 켜져 있어야 하며, 특정패킷(MagicPacket)을 받았을때 켜지면 된다.
Python script to enable WakeOnLan
1 import socket
2 import struct
3
4 def wake_on_lan(macaddress):
5 """ Switches on remote computers using WOL. """
6
7 # Check macaddress format and try to compensate.
8 if len(macaddress) == 12:
9 pass
10 elif len(macaddress) == 12 + 5:
11 sep = macaddress[2]
12 macaddress = macaddress.replace(sep, '')
13 else:
14 raise ValueError('Incorrect MAC address format')
15
16 # Pad the synchronization stream.
17 data = ''.join(['FFFFFFFFFFFF', macaddress * 20])
18 send_data = ''
19 # Split up the hex values and pack.
20 for i in range(0, len(data), 2):
21 send_data = ''.join([send_data,
22 struct.pack('B', int(data[i: i + 2], 16))])
23
24 # Broadcast it to the LAN.
25 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
26 sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
27 sock.sendto(send_data, ('<broadcast>', 7))
28
29 if __name__ == '__main__':
30 # Use macaddresses with any seperators.
31
32 wake_on_lan('0F:0F:DF:0F:BF:EF')
33 wake_on_lan('0F-0F-DF-0F-BF-EF')
34 # or without any seperators.
35 wake_on_lan('0F0FDF0FBFEF')