Created
November 6, 2010 20:22
-
-
Save wyanez/665692 to your computer and use it in GitHub Desktop.
Wake-On-Lan (Encendido de PC Automático desde la red para equipos que incorporen esta característica)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wake-On-LAN | |
# | |
# Copyright (C) 2002 by Micro Systems Marc Balmer | |
# Written by Marc Balmer, [email protected], http://www.msys.ch/ | |
# This code is free software under the GPL | |
import struct, socket | |
def WakeOnLan(ethernet_address): | |
# 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)) | |
# Build the Wake-On-LAN "Magic Packet"... | |
msg = '\xff' * 6 + hw_addr * 16 | |
# ...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>', 9)) | |
s.close() | |
# Example use | |
WakeOnLan('00:11:09:62:ea:97') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment