WOL (Wake on LAN) script - start a computer remotly

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
kricker Offline
Team-XBMC QA Specialist
Posts: 3,308
Joined: Apr 2004
Reputation: 16
Location: Knoxville, TN
Post: #21
I am trying to get my Xbox to send a WOL to my server when XBMC starts. I understand how to use autoexec.py. The problem lies in trying to find the correct WOL script. I have the tweaked WOL, but it opens a GUI to select the PC to wake. This is great if I have other computers to wake, but I want it to always wake the server and not show a GUI when running at startup. All my searches for the older WOL showed either dead links or the code I lifted from the posts did nothing. Can anyone please help me out?

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
ozNick Offline
Junior Member
Posts: 26
Joined: Jan 2007
Reputation: 0
Post: #22
kricker Wrote:I am trying to get my Xbox to send a WOL to my server when XBMC starts. I understand how to use autoexec.py. The problem lies in trying to find the correct WOL script. I have the tweaked WOL, but it opens a GUI to select the PC to wake. This is great if I have other computers to wake, but I want it to always wake the server and not show a GUI when running at startup. All my searches for the older WOL showed either dead links or the code I lifted from the posts did nothing. Can anyone please help me out?

I had a look and couldn't find it so the code is below (change the MAC). You can wake more than 1 by duplicating the WakeOnLan(MAC) line.

Alternatively you can use Nuka's Plug-in maker (in SVN) to send a WOL packet when the desired share is required.


Cheers Nick

Code:
# 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('aa:bb:cc:dd:ee:ff')    # My PC
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,308
Joined: Apr 2004
Reputation: 16
Location: Knoxville, TN
Post: #23
That is the exact code I tried to lift and use. When I run it nothing happens. If I run the tweaked WOL script it works properly.

I looked for Nuka's Plug-in maker and could not find it. Is it only in the SVN? So I need to find it there? I'd love for it to only send the WOL when the share is requested. That is even better than always waking the server at boot up.

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,308
Joined: Apr 2004
Reputation: 16
Location: Knoxville, TN
Post: #24
I got the script working now. I changed the port from 9 to 7. I thought I did that before and it didn't work...oh well. It is now. Smile

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
ozNick Offline
Junior Member
Posts: 26
Joined: Jan 2007
Reputation: 0
Post: #25
kricker Wrote:That is the exact code I tried to lift and use. When I run it nothing happens. If I run the tweaked WOL script it works properly.
I tested before I posted, and copied and pasted from the forums just to double check, and it all works fine. Have you tested as just a standalone script?

kricker Wrote:I looked for Nuka's Plug-in maker and could not find it. Is it only in the SVN? So I need to find it there? I'd love for it to only send the WOL when the share is requested. That is even better than always waking the server at boot up.
The repositry is covered in this thread http://forum.xbmc.org/showthread.php?tid=29911

The plug-in created uses a modified version of the script I posted.

Cheers Nick
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,308
Joined: Apr 2004
Reputation: 16
Location: Knoxville, TN
Post: #26
Thanks for the info. Look above, I got it working. I'm not sure why it didn't earlier. Maybe a bad copy paste. Thanks again.

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,308
Joined: Apr 2004
Reputation: 16
Location: Knoxville, TN
Post: #27
Followup,
So now that I got the script working, I ended up just adding:
Code:
<onclick>XBMC.RunScript(Q:\scripts\Wake\wakePVR.py)</onclick>
to the items on the home screen that access content on that computer. This way it only wakes that PC when it needs content from it. So far it works like a champ. The only downside is having to edit the homescreen whenever I update the skin.

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
zackpliskin Offline
Senior Member
Posts: 144
Joined: Dec 2008
Reputation: 0
Post: #28
Thanks ozNick... that standard WOL python script works great, and will power on my computer from S3 when PME is enabled in the BIOS, just as I wanted.

There is one thing I can't seem to resolve though: booting to and shutting down the system from Windows with the device manager options set to allow booting via ethernet magic packets means WOL works flawlessly every time, but if I don't the WOL will not work. It's not a big deal because Windows is what I use 99% of the time but I'd like it so WOL works regardless of whether it was shut down from Windows, just in case I forget or whatever.
(This post was last modified: 2010-05-25 16:00 by zackpliskin.)
find quote
castortray Offline
Fan
Posts: 502
Joined: May 2009
Reputation: 0
Post: #29
Hi,

I use MySQL which is installed on my Asrock with Windows 7 in living room.
I don't use it all the time, so it automacicallly go to "sleep".

When is in "sleep" mode I can't (not able to connect to MySQL) run xbmc client on other laptop before I turn on Asrock. How I can send "wake on lan" to my Asrock before or during start client on another PC/laptop ?

many thanks for any tips,

regards
find quote
Post Reply