Skip to content

Commit

Permalink
format file
Browse files Browse the repository at this point in the history
  • Loading branch information
soapmancn committed Jan 15, 2024
1 parent 05a43da commit 8459002
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

app = Flask(__name__)


def send_wol_magic_packet(mac_address, broadcast_ip="255.255.255.255", port=9):
mac_bytes = binascii.unhexlify(mac_address.replace(":", "").replace("-", ""))
magic_packet = b'\xFF' * 6 + mac_bytes * 16
Expand All @@ -12,6 +13,7 @@ def send_wol_magic_packet(mac_address, broadcast_ip="255.255.255.255", port=9):
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto(magic_packet, (broadcast_ip, port))


@app.route('/wol', methods=['POST'])
def wake_on_lan():
data = request.get_json()
Expand All @@ -24,5 +26,6 @@ def wake_on_lan():
send_wol_magic_packet(target_mac_address)
return jsonify({'message': 'Wake-on-LAN信号已发送'})


if __name__ == '__main__':
app.run(debug=True)

0 comments on commit 8459002

Please sign in to comment.