WOL via Web Script

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
damdy-cash
Experienced User
Posts: 102
Joined: Tue Mar 28, 2006 6:48 am

WOL via Web Script

Post by damdy-cash » Tue Feb 19, 2008 5:29 pm

I have found this Python script for WOL via internet:

Code: Select all

# 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, ('your.homeip.net', 9))
  s.close()

# Example use
WakeOnLan('00:70:9d:87:66:ca')
you only have to change your Adresse at 'your.homeip.net' and the Mac in the last line.
Last edited by damdy-cash on Wed Feb 27, 2008 11:04 pm, edited 1 time in total.
Gruß Damdy

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: WOL via Web Script

Post by Bitmonster » Wed Feb 27, 2008 6:09 pm

What is the benefit of this script compared to to the built-in function?
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!

damdy-cash
Experienced User
Posts: 102
Joined: Tue Mar 28, 2006 6:48 am

Re: WOL via Web Script

Post by damdy-cash » Wed Feb 27, 2008 10:46 pm

Hi Lars,

nice to see you active again :)
With this script it work for me to start a PC in my privat network via web with my dyndns address. Not only to a MAC address inside a privat network like in the existing EG solution.

To get it work you will need additional a router with broadcast ability. In my example the router give the udp port 9 via NAT to the broadcast ip 192.168.0.255 and so the magic packet from the WOL will be send to all PC in my privat network.
Not any Router has the ability to make a NAT to this brodcast ip. To be exact, my netgear cant, my arcor can do it.
Last edited by damdy-cash on Wed Feb 27, 2008 10:52 pm, edited 1 time in total.
Gruß Damdy

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: WOL via Web Script

Post by Bitmonster » Wed Feb 27, 2008 10:48 pm

Ah, I see.
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!

Post Reply