Skip to content

Instantly share code, notes, and snippets.

@fliphess
Created December 21, 2017 15:01
Show Gist options
  • Save fliphess/d566393983fa33465664e10f2adc5cef to your computer and use it in GitHub Desktop.
Save fliphess/d566393983fa33465664e10f2adc5cef to your computer and use it in GitHub Desktop.
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
Copy link

QSKONE commented May 6, 2019

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

@Dimonyga
Copy link

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

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

@dim-geo
Copy link

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