Page 1 of 1

WOL via Web Script

Posted: Tue Feb 19, 2008 5:29 pm
by damdy-cash
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.

Re: WOL via Web Script

Posted: Wed Feb 27, 2008 6:09 pm
by Bitmonster
What is the benefit of this script compared to to the built-in function?

Re: WOL via Web Script

Posted: Wed Feb 27, 2008 10:46 pm
by damdy-cash
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.

Re: WOL via Web Script

Posted: Wed Feb 27, 2008 10:48 pm
by Bitmonster
Ah, I see.