Skip to content

Instantly share code, notes, and snippets.

@fliphess fliphess/wol.py
Created Dec 21, 2017

Embed
What would you like to do?
Wake up post 2016 Philips TV's using Wake on Lan
#!/usr/bin/env python3
import struct
import re
import socket
import sys
MAC = '1c:5a:6b:b8:93:c0'
def wake_on_lan(mac):
if len(mac) == 12:
pass
elif len(mac) == 12 + 5:
mac = mac.replace(mac[2], '')
else:
raise ValueError('Incorrect MAC address format')
data = ''.join(['FFFFFFFFFFFF', mac * 16])
# Split up the hex values and pack.
send_data = b''
for i in range(0, len(data), 2):
send_data = b''.join([send_data, struct.pack('B', int(data[i: i + 2], 16))])
# Broadcast it to the LAN.
for _ in range(15):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(send_data, ('172.16.15.255', 9))
if __name__ == '__main__':
# mac = get_mac_address(sys.argv[1])
# print(mac)
wake_on_lan(MAC)
@QSKONE

This comment has been minimized.

Copy link

QSKONE commented May 6, 2019

Hi , What a ip numbers you use in line 29?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.