Wake-on-LAN via Python?

Tim Howarth tim at worthy.demon.co.uk
Wed Aug 15 03:54:58 EDT 2001


In message <3B79C006.MD-1.4.15.angband at blueyonder.co.uk>
          "Bablos" <angband at blueyonder.co.uk> wrote:

> Has anyone managed to implement Wake-on-LAN via Python?  I assume it's
> possible, but I'm not sure what kind of programming would be involved,
> and what kind of information would need to be sent to a machine on a
> LAN in order to wake it up.


There's probably a better way to do it but this is what I did, where
AABBCCDDEEFF is the MAC address of the machine you wish to wake.


MYPORT = 50000

from socket import *

s = socket(AF_INET, SOCK_DGRAM)
s.bind(('', 0))
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)

data = 'FFFFFFFFFFFF'
data+= 'AABBCCDDEEFF'*16
sd=''

for a in range(0,len(data),2):
    sd+=chr(int(data[a:a+2],16))

s.sendto(sd, ('<broadcast>', MYPORT))



-- 
___
 |im    ---- ARM Powered ----



More information about the Python-list mailing list