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

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
jepper Offline
Member
Posts: 52
Joined: Nov 2006
Reputation: 0
Post: #16
ow and it has a really ugly icon Tongue
find quote
JoJa15 Offline
Junior Member
Posts: 2
Joined: Feb 2007
Reputation: 0
Post: #17
I am working on an advanced Wake On Lan script for XBMC. So far the WOL function is working and I would like to add the ability to show if a machine is up or off (I figured I would do so by pinging the machine and seeing if I get a response). I would also like to add the ability to remotely shutdown a computer from the XBMC script. Does anyone have a code snippet for pinging an IP, a code snippet for shutting down a remote Windows machine, and a code snippet for sending a HTTP request?

Here is my current setup:

Latest XBMC
FreeNAS (media server running on FreeBSD. Can be shutdown from web interface so I planned on just sending that same web button click from XBMC to shutdown the FreeNAS server)
Windows XP machine with folder share (What packet is sent over the network to remotely shutdown a Windows XP machine?)

My hope is to have a script then when you start it will list all your remote computers/servers and show if they are currently on/off. Then you can select a server and turn it off if it is on or turn it on if it is off.

Thank you in advance for any help provided.

- John
find quote
timdog82001 Offline
Posting Freak
Posts: 1,135
Joined: Mar 2006
Reputation: 0
Post: #18
I don't know if its completely necessary, but I know the shutdown on lan script already on xbmcscripts uses a client that you have to run on the computer in order to to tell it to shutdown...Would be great if you could do it without it though
find quote
mwg47x Offline
Junior Member
Posts: 1
Joined: Apr 2007
Reputation: 0
Post: #19
JoJa15,
Did you ever get this working the way you wanted?
I'd be interested in seeing it if you wouldn't mind.
find quote
wigwam Offline
Member
Posts: 52
Joined: Apr 2007
Reputation: 0
Post: #20
i would also like to try this so anyone who has it working please tell us what to do!

Xbox Ver 1.0; XBMC 2.0.1; PMIII Skin
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,419
Joined: Apr 2004
Reputation: 20
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,419
Joined: Apr 2004
Reputation: 20
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,419
Joined: Apr 2004
Reputation: 20
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,419
Joined: Apr 2004
Reputation: 20
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,419
Joined: Apr 2004
Reputation: 20
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: 145
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: 501
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