import socket
def broadcaste(data):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
# network = '<broadcast>'
network = '192.168.1.255'
port = 9
dest = (network, port)
s.sendto(data, dest)
def wol(mac):
mac = mac.replace(":", "")
data = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
mac_bytes = bytes.fromhex(mac)
# print(mac_bytes)
data = bytearray(data)
# print(data)
for i in range(16):
data = data+mac_bytes
# print(data)
broadcaste(data)
if __name__ == '__main__':
mac = "2c:f0:5d:27:56:ef"
for i in range(20):
wol(mac)