PDA

View Full Version : Python Wake-on-Lan script ( WOL your PC )


arturhs
2004-02-15, 00:12
hi all,

today i tried to build a wake-on-lan script to wake up my computer from xbmc. i got a simple script from internet and tried it on xbmc:

import socket

s=socket.socket(socket.af_inet, socket.sock_dgram)
s.sendto('\xff'*6+'\x00\x50\x2c\x01\x99\x52'*16, ('192.168.200.255',9))

this script creates a magic packet tha has the data portion full-filled with six ff pairs and 16 times the mac addres of my computer.

i've tried all the noon to make it work but nothing. so, i've realized that i was having some packet generation problem. i've installed a sniffer and windows python on my notebook. i've discovered that this script works well on windows python a the magic packet is sended to the broadcast address of my network.

when i try to do the same think with the same script running on xbox, the xbmc python socket sends an arp resolution packet trying to figure out who is the host 192.168.200.255. i think that this could be a tcp/ip problem, because this address is a broadcast address for the network, and the tcp/ip knows that.

because o this the wake-on-lan script is not working on xbmc python, but works ok with windows python.

if some one could help, or the xbmc python developers could help we will be pleased.

darkie
2004-02-15, 00:41
try '255.255.255.255' as the broadcast address instead of '192.168.200.255'. only the first one seems to work on the xbox

arturhs
2004-02-15, 00:54
hi darkie...

i've tried with 255.255.255.255 too, but doen't work. no packets are generated on the network with this.

i think that it don't work with this general broadcast address, for the same reason that, with this this address, the windows python don't work:

traceback (most recent call last):
file "c:\wakeonlan.py", line 4, in -toplevel-
s.sendto('\xff'*6+'\x00\x50\x2c\x01\x99\x52'*16, ("255.255.255.255",9))
error: (10013, 'permission denied')

this is a trace from the windows python version. seems that with the *nix oss this address works ok.

no packets on the network are gerenated at all.

arturhs
2004-02-15, 01:07
ok.. it's working now.... the magic packet are being created by xbmc python....

import socket

s=socket.socket(socket.af_inet, socket.sock_dgram)
s.setsockopt(socket.sol_socket, socket.so_broadcast, 1)
s.sendto('\xff'*6+'\x00\x50\x2c\x01\x99\x52'*16, ("255.255.255.255",9))

searching on internet, i've founded that i need to declare the sockets options before sending a packet to a broadcast address. now it's working!!! just copy the script and change the mac address (00 50 2c 01 99 52) with the one of your network board.

you will need to be sure that your computer supports wake-on-lan. to have sure of this, view your network board features and your motherboard bios.

darkie
2004-02-15, 01:08
try this one, it generates packets on my xbox.
only problem is my pc doesn't wake up, but that has probably something to do with my pc.

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>', 7))
*s.close()

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

Gamester17
2004-02-15, 20:35
k, but wouldn't it be much better to implement this in c++ and native xbmc/xbox, as much more memery efficient than python?

GeminiServer
2004-02-21, 05:28
lööööööl :d :d :d


i was searching and coding the python script to get work wol! and it works on my xbox after 2 days python coding! and what i see here is.. you guys done it before...

on the next time, i'll look here before doing something http://www.xboxmediaplayer.de/forums/non-cgi/emoticons/tounge.gif


regards
geminiserver

Timbay
2004-05-06, 02:53
hi guys!

great that some of you have the same idea.....has anybody of you ....found out if theire is a xbe that to the same....or this feature will come in xbmc ?

would be cool!

greetingz

timay

NikosKos
2004-06-24, 17:08
i've found this little python script which i find very useful. it saved me several times from walking to my pc just to turn it on.

it sends a wake-on-lan packet through the network.

1.- download the following file :
http://gsd.di.uminho.pt/jpo....hon.txt (http://gsd.di.uminho.pt/jpo/software/wakeonlan/mini-howto/wolpython.txt)

2.- save it as "whatever.py"
ex : wol.py

3.- open it with a simple text editor (notepad)
and edit the last line of the script
this one : wakeonlan('0:3:93:81:68:b2')

4.- replace the value between quotes with your own mac address and save the file.

5.- place the file in your script directory on your xbox.

you can now launch the script to turn your computer on and access your shared dirs without moving your fat ass from the sofa.

ps : your computer must support wake-on-lan and your bios must be configured as well. if you don't know what i'm talking about, forget it :)

edit : my search through the forum for 'wake' or 'wol' didn't give me any result, so sorry if i'm talking about something that's been already discussed. :)

Anomaly
2004-06-25, 08:18
for what it's worth, using "wake" as a search term comes up immediately with this thread ???

NikosKos
2004-06-25, 11:16
now, it does. thanks to this sentence :

edit : my search through the forum for 'wake' or 'wol' didn't give me any result, so sorry if i'm talking about something that's been already discussed.

:)

jamal
2004-06-25, 20:53
how can i see my mac address ?

thank you... ???

tslayer
2004-06-26, 00:32
goto a command prompt in windows (start->run->cmd).

then type:

ipconfig /all

look for your ethernet adapter.

and you will see something like:

physical address. . . . . . . . . : 00-0d-61-0c-4a-d2

there ya go.

ts

jamal
2004-06-26, 15:48
thank you

bakashrimp
2005-01-03, 09:12
sorry to bump such an old thread, but this script works very nice. thanks.

d.i.z
2005-01-04, 00:57
is it posibble to send such packet through internet?

it could be too much of security risk so i guess not, but maybe...?

djmattyg007
2009-07-28, 12:49
in case anyone is wondering, yes, it is possible to send a WOL packet over the internet (to answer the previous poster)

spiff
2009-07-28, 12:50
ooh, i bet he has been waiting for that answer the last 4 years! :)

flighttothemoon
2009-10-01, 20:32
Is it possible to make this script start when XBMC starts? Not to start the script manually.

javiertoti
2009-10-26, 18:20
i've found this little python script which i find very useful. it saved me several times from walking to my pc just to turn it on.

it sends a wake-on-lan packet through the network.

1.- download the following file :
http://gsd.di.uminho.pt/jpo....hon.txt (http://gsd.di.uminho.pt/jpo/software/wakeonlan/mini-howto/wolpython.txt)

2.- save it as "whatever.py"
ex : wol.py

3.- open it with a simple text editor (notepad)
and edit the last line of the script
this one : wakeonlan('0:3:93:81:68:b2')

4.- replace the value between quotes with your own mac address and save the file.

5.- place the file in your script directory on your xbox.

you can now launch the script to turn your computer on and access your shared dirs without moving your fat ass from the sofa.

ps : your computer must support wake-on-lan and your bios must be configured as well. if you don't know what i'm talking about, forget it :)

edit : my search through the forum for 'wake' or 'wol' didn't give me any result, so sorry if i'm talking about something that's been already discussed. :)



Sorry master, i've just downloaded your code and doesn't work with my cpu.

# Wake-On-LAN
#
# Copyright (C) 2002 by Micro Systems Marc Balmer
# Written by Marc Balmer, marc@msys.ch, 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:22:15:37:F7:57')

Methanoid
2009-10-29, 23:36
rename it to autoexec.py ??

javiertoti
2009-11-01, 02:33
Doesn't work

# Wake-On-LAN
#
# Copyright (C) 2002 by Micro Systems Marc Balmer
# Written by Marc Balmer, marc@msys.ch, 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:22:15:37:F7:57')



What is wrong?