Search code examples
pythonhtmlsynologywake-on-lan

Python WoL Script won't run on Synology RS1221+ but on QNAP TS-219P II


I'm relatively new to Python and I don't understand why the same script doesn't run on my RS1221+ NAS but does on the QNAP ts-219p ii without problems. It's a WoL script designed to turn on specific PCs via an HTML page. You press on a PNG image which then calls a php script which then calls said Python script.

I simply copied the php and python script from my colleague. It works on the QNAP ts-219p NAS system but not on the newer RS1221+. Following packages are already installed on the new system: Python 3.9, Node.js v 18 and php 8.0.

In Web Station on the RS1221+ Python is activated and shows green. The module "wakeonlan" version 3.0.0 is also installed in the "edit" section.

This is the php script that calls the python script (with the x's being placeholders and changed for the Mac of the PC I want to turn on). My Network Address is 192.168.0.1 /23:

<?php
system ( "python wake.py 192.168.1.255 XX:XX:XX:XX:XX:XX");
header ("Location:index.html");
?>

This is the python script (wake.py) I'm using for WoL thats called and should run on the server:

import socket
import sys
 
if len(sys.argv) < 3:
    print("Usage: wakeonlan.py <ADR> <MAC>     (example: 192.168.1.255 00:11:22:33:44:55)")
    sys.exit(1)
 
mac = sys.argv[2]
data = ''.join(['FF' * 6, mac.replace(':', '') * 16])
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(data.decode("hex"), (sys.argv[1], 9))

I've already tried changing the Python script to use another module:

from wakeonlan import send_magic_packet

send_magic_packet('XX-XX-XX-XX-XX-XX')

but this didn't work either. As I said, I'm not a master in python and thats why I would be thankful for all suggestions.


Solution

  • For anyone comming back to this problem:

    Using this https://pypi.org/project/wakeonlan/ package for Python solved all my problems I had.