-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoorBellService.py
executable file
·63 lines (51 loc) · 2.24 KB
/
DoorBellService.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
59
60
61
62
63
import socket
import sys
from thread import *
import winsound
import win32evtlogutil
import win32api
import win32con
import win32security # To translate NT Sids to account names.
import win32evtlog
logType = "Application"
ApplicationName="DoorBellService.py"
win32evtlogutil.ReportEvent(logType, 0,strings=['DOORBELL SERVICE READY'],
eventType=win32evtlog.EVENTLOG_INFORMATION_TYPE,
data = "Raw\0Data".encode("ascii"))
def DoorBellService():
HOST = '' # Symbolic name meaning all available interfaces
PORT = 9999
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#print 'Socket created'
try:
s.bind((HOST, PORT))
except socket.error , msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
win32evtlogutil.ReportEvent(logType, 2,strings=['Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1],"ERROR DOORBELL"],
data = "Raw\0Data".encode("ascii"))
sys.exit()
#print 'Socket bind complete'
s.listen(10)
#print 'Socket now listening'
#Function for handling connections
def clientthread(conn):
#Sending message to connected client
#conn.send('Welcome to the server. Receving Data...\n') #send only takes string
conn.close()
#now keep talking with the client
while 1:
#wait to accept a connection
conn, addr = s.accept()
#print 'Connected with ' + addr[0] + ':' + str(addr[1])
win32evtlogutil.ReportEvent(logType, 0,strings=['Connected with ' + addr[0] + ':' + str(addr[1])],
eventType=win32evtlog.EVENTLOG_INFORMATION_TYPE,
data = "Raw\0Data".encode("ascii"))
try:
winsound.PlaySound('C:\Users\Public\Music\doorbell1.wav',winsound.SND_FILENAME)
except msg:
win32evtlogutil.ReportEvent(logType, 2,strings=['Ring failed Error Code : ' + str(msg[0]) + ' Message ' + msg[1],"ERROR DOORBELL"],
data = "Raw\0Data".encode("ascii"))
#start new thread
start_new_thread(clientthread ,(conn,))
s.close()
x = DoorBellService()