-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLGTV.cgi
43 lines (33 loc) · 1.17 KB
/
LGTV.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
# use this code for turning lg TV on or off
# you will need to set up access on the LG TV, it needs to be a commercial series display
# for this code to work, newer consumer displays require an encryption key for the commands
# for newer than 2018 models that require keycodes, look up Wes Souza in github, there is a working
# json library for the AES-128 encryption required for newer than 2018 model LG TVs
# with npm installed, sudo npm i lgtv-ip-control-cli for the npm library with Command Line Interface
import cgitb
import urllib2
import time
from datetime import datetime
import sys
import socket
cgitb.enable()
from wakeonlan import send_magic_packet
print 'content-type: text/html\r\n'
cmd = sys.argv[1]
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
PORT = 9761
lgTVON = 'ka 00 01'
lgTVOFF = 'ka 00 00'
if cmd == 'lgtvON':
send_magic_packet('[Specified TV's MAC Adreess]')
elif cmd == 'lgtvOFF':
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
sock.connect(([Specified TV's IP address], PORT))
sock.sendall(lgTVOFF + '\r')
msg = sock.recv(9761)
print msg
sock.close()
else:
print ('no match for command')