Created
November 18, 2020 23:27
-
-
Save nicolalamacchia/38b3459366e16df71a65c73444bc2d94 to your computer and use it in GitHub Desktop.
Wake-on-LAN in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import socket | |
import struct | |
import sys | |
BROADCAST_IP = "192.168.0.255" | |
MAC_ADDRESS = "00:00:00:00:00:00" | |
WOL_PORT = 9 # 0, 7 or 9 | |
bin_mac_address = struct.pack( | |
"B" * 6, | |
*(int(i, 16) for i in MAC_ADDRESS.split(":")) | |
) | |
magic_packet = "{}{}".format("\xff" * 6, bin_mac_address * 16) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
sock.sendto(magic_packet, (BROADCAST_IP, WOL_PORT)) | |
sock.close() | |
print("OK") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment