-
Notifications
You must be signed in to change notification settings - Fork 14
/
samsung-msgbox.py
executable file
·58 lines (47 loc) · 3.5 KB
/
samsung-msgbox.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
# Developed by Shantanu Goel. http://tech.shantanugoel.com/
import socket
import argparse
import time
#Defaults
port = 52235
receiver_no = "1234567890"
sender_no = "1234567890"
receiver = "Receiver"
sender = "Sender"
epochtime = time.mktime(time.localtime())
def buildMessage(args):
body = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>" + " <u:AddMessage xmlns:u=\"urn:samsung.com:service:MessageBoxService:1\">" + " <MessageType>text/xml</MessageType>" + " <MessageID>MessageId</MessageID>" + "<Message>" + "<Category>SMS</Category>" + "<DisplayType>Maximum</DisplayType>" + "<ReceiveTime>" + "<Date>" + time.strftime('%Y-%m-%d', time.localtime(args.time)) + "</Date>" + "<Time>" + time.strftime('%H:%M:%S', time.localtime(args.time)) + "</Time>" + "</ReceiveTime>" + "<Receiver>" + "<Number>" + args.receiver_no + "</Number>" + "<Name>" + args.receiver + "</Name>" + "</Receiver>" + "<Sender>" + "<Number>" + args.sender_no + "</Number>" + "<Name>" + args.sender + "</Name>" + "</Sender>" + "<Body>" + args.msg + "</Body>" + "</Message>" + " </u:AddMessage>" + " </s:Body>" + "</s:Envelope>";
host = socket.gethostname()
length = len(body)
header = "POST /PMR/control/MessageBoxService HTTP/1.0\r\n" + "Content-Type: text/xml; charset=\"utf-8\"\r\n" + "HOST: " + host + "\r\n" + "Content-Length: " + str(length) + "\r\n" + "SOAPACTION: \"uuid:samsung.com:service:MessageBoxService:1#AddMessage\"\r\n" + "Connection: close\r\n" + "\r\n"
message = header + body
print message
return message
def sendMessage(args, message):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.connect((args.ip, args.port))
sent = s.send(message)
if (sent <= 0):
print("Error Sending Message")
s.close()
return
recv = s.recv(100000)
print recv
s.close()
def main():
parser = argparse.ArgumentParser(description='Send an arbitrary text message to Samsung TVs which is displayed onscreen. Developed by Shantanu Goel (http://tech.shantanugoel.com/) version 1.0', add_help = False)
flags = parser.add_argument_group('Arguments')
flags.add_argument('-i', '--ip', dest = 'ip', default = None, help = 'Required. IP Address of the TV', required = True)
flags.add_argument('-m', '--msg', dest = 'msg', default = None, help = 'Required. Message body text to be sent to TV', required = True)
flags.add_argument('-p', '--port', dest = 'port', default = port, type = int, help = 'Optional. Port on which message should be sent')
flags.add_argument('-t', '--time', dest = 'time', default = epochtime, type = float, help = 'Optional. Receive date and time in epoch/unix format')
flags.add_argument('-r', '--receiver', dest = 'receiver', default = receiver, help = 'Optional. Receiver Name')
flags.add_argument('-x', '--receiverno', dest = 'receiver_no', default = receiver_no, help = 'Optional. Receiver Number')
flags.add_argument('-s', '--sender', dest = 'sender', default = sender, help = 'Optional. Sender Name')
flags.add_argument('-y', '--senderno', dest = 'sender_no', default = sender_no, help = 'Optional. Sender Number')
flags.add_argument('-h', '--help', action='help')
args = parser.parse_args()
message = buildMessage(args)
sendMessage(args, message)
main()