ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/WakeOnLan.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
File size: 1351 byte(s)
Log Message:
Initial Import

File Contents

# User Rev Content
1 ninoborges 8 ## WakeOnLan.py
2     ## Turns on a workstation through lan
3     import socket
4     import struct
5    
6     def wake_on_lan(macaddress):
7     """ Switches on remote computers using WOL. """
8    
9     # Check macaddress format and try to compensate.
10     if len(macaddress) == 12:
11     pass
12     elif len(macaddress) == 12 + 5:
13     sep = macaddress[2]
14     macaddress = macaddress.replace(sep, '')
15     else:
16     raise ValueError('Incorrect MAC address format')
17    
18     # Pad the synchronization stream.
19     data = ''.join(['FFFFFFFFFFFF', macaddress * 20])
20     send_data = ''
21    
22     # Split up the hex values and pack.
23     for i in range(0, len(data), 2):
24     send_data = ''.join([send_data,
25     struct.pack('B', int(data[i: i + 2], 16))])
26    
27     # Broadcast it to the LAN.
28     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
29     sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
30     sock.sendto(send_data, ('<broadcast>', 7))
31    
32    
33     if __name__ == '__main__':
34     tower = '00:19:B9:23:5B:F6'
35     main_Workstation = '00-21-70-32-29-EE'
36     #eab_test_w2k = '00:B0:D0:DA:FE:50'
37     #ps_mediastation = '00:0C:F1:70:9B:B4'
38     electronicode = ''
39     #wake_on_lan(ps_mediastation)
40     wake_on_lan(main_Workstation)
41     #wake_on_lan('0F:0F:DF:0F:BF:EF')
42     #wake_on_lan('0F-0F-DF-0F-BF-EF')
43