Skip to content

Instantly share code, notes, and snippets.

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 QSKONE commented May 6, 2019

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

@Dimonyga

This comment has been minimized.

Copy link

@Dimonyga Dimonyga commented Jan 19, 2020

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

i's broadcast network address
https://en.wikipedia.org/wiki/Broadcasting_(networking)

@dim-geo

This comment has been minimized.

Copy link

@dim-geo dim-geo commented Feb 15, 2021

For my TV via WoWLAN you have to send the packet to 255.255.255.255 and you have to wake the TV via pylips.
For anyone interested, check my forked gist. wol.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment