Python WoL script fails on Synology RS1221+ but runs successfully on QNAP TS-219P II
P粉395056196
P粉395056196 2024-02-17 16:02:35
0
1
441

I'm relatively new to Python and I don't understand why the same script doesn't run on my RS1221 NAS but runs on the QNAP ts-219p ii with no issues. It is a WoL script designed to open a specific PC via an HTML page. You press a PNG image, which then calls a php script, which in turn calls said Python script.

I just copied the php and python scripts from a colleague. It works with the QNAP ts-219p NAS system, but not the newer RS1221. The following packages are installed on the new system: Python 3.9, Node.js v 18, and php 8.0.

In Web Station on RS1221, Python is activated and appears green. Module "wakeonlan" version 3.0.0 is also installed in the "Editing" section.

This is the php script that calls the python script (where x is a placeholder and changed for the Mac which is the PC I want to open). 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 my python script (wake.py) for WoL that is 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 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 doesn't work either. As I said, I'm no python guru, that's why I'd appreciate any advice.

P粉395056196
P粉395056196

reply all(1)
P粉955063662

For anyone coming back to this question:

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!