问题描述
尝试使用 RaspBerry Pi 4 作为网络中其他设备的网络唤醒集线器。以下脚本可通过 Windows 和 Ubuntu Server 18.04 运行,但不能通过 Raspian Buster 运行。这是利用 wakeonlan 模块。
from wakeonlan import send_magic_packet;
def wakeup():
send_magic_packet('_MAC_',ip_address='_subnet_.255',port=9)
if __name__ == "__main__":
wakeup()
在 Raspbian 上使用时,出现权限错误:
Traceback (most recent call last):
File "foo.py",line 7,in <module>
wakeup()
File "foo.py",line 4,in wakeup
send_magic_packet('_MAC_',port=9)
File "/usr/local/lib/python3.7/dist-packages/wakeonlan.py",line 58,in send_magic_packet
sock.send(packet)
PermissionError: [Errno 1] Operation not permitted
如您所见,这是通过 Python 3 运行的,我尝试使用 sudo
运行脚本,结果相同。通过提升的 Python 3 shell 运行它不会产生错误,但也不会产生任何结果。
这是错误中引用的 import
的 wakeonlan.py
import argparse
import socket
from typing import List
以及有问题的函数,即第 36 行到第 58 行。
def send_magic_packet(
*macs: str,ip_address: str = broADCAST_IP,port: int = DEFAULT_PORT
) -> None:
"""
Wake up computers having any of the given mac addresses.
Wake on lan must be enabled on the host device.
Args:
macs: One or more macaddresses of machines to wake.
Keyword Args:
ip_address: the ip address of the host to send the magic packet to.
port: the port of the host to send the magic packet to.
"""
packets = [create_magic_packet(mac) for mac in macs]
with socket.socket(socket.AF_INET,socket.soCK_DGRAM) as sock:
sock.setsockopt(socket.soL_SOCKET,socket.so_broADCAST,1)
sock.connect((ip_address,port))
for packet in packets:
sock.send(packet)
我不知道如何解决,因为它适用于 Ubuntu Server 和 Windows。任何意见,将不胜感激。我已经阅读了 socket
和 Python 的潜在权限问题,但找不到任何似乎适用于此问题的具体内容。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)